Vuejs 中的 Discourse 评论

我有一个使用 Vue.js 的网站和一个 Discourse 论坛。我试图在模板文件中插入一段 JavaScript,将论坛的评论连接到 Vue.js 网站的特定页面上,但我遇到了以下错误:

Templates should only be responsible for mapping the state to the UI. 
Avoid placing tags with side-effects in your templates, such as <script>,
as they will not be parsed.

我尝试将 text/javascript 改为 application/javascript,但在渲染时收到了以下错误:

 - invalid expression: missing ) after argument list in

" \n  DiscourseEmbed = { discourseUrl: 'https://forum.epicseven.ru/',\n                     \ndiscourseEmbedUrl: '"+_s(url absolute="true")+"' };\n\n  (function() {\n    \nvar d = document.createElement('script'); d.type = \n'application/javascript'; d.async = true;\n    d.src = \nDiscourseEmbed.discourseUrl + 'javascripts/embed.js';\n    \n(document.getElementsByTagName('head')[0] || \ndocument.getElementsByTagName('body')[0]).appendChild(d);\n  })();\n"

  Raw expression: DiscourseEmbed = { discourseUrl: 
'https://forum.epicseven.ru/',
                 discourseEmbedUrl: '{{url absolute="true"}}' };

  (function() {
    var d = document.createElement('script'); d.type = 
'application/javascript'; d.async = true;
    d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
    (document.getElementsByTagName('head')[0] || 
document.getElementsByTagName('body')[0]).appendChild(d);
  })();

据我理解,在 Vue.js 中使用 JS 文件仅限于从调用来源的域进行加载。而我的论坛设置在了子域名上。

我该如何修复这个错误?是否应该尝试使用代码的其他部分?

The embedding code we provide is meant for static sites, not client side rendered (SPAs) like Vue/React/Ember/Angular.

You will have to look into another method of obtaining the data from Discourse. We do offer a full API but you might have to proxy it through your own server to avoid cross domain requests.

3 个赞

我在单页应用程序中遇到了同样的问题,经过一些调整,这里有一个可能的解决方案:Embed comments from Discourse in your single page app

此主题在上次回复后 30 天自动关闭。不再允许回复。