【发布时间】:2018-03-05 09:25:53
【问题描述】:
我是 html、javascript 和 vue 的新手。我不确定这是 vue 特有的还是可以使用一些 javascript 魔法来解决的。
我有基于 NodeJS 的服务,它的 UI 是用 VueJS 编写的。页面内容来自 Markdown 编辑器,nodejs 使用 showdown 将其转换为 html。 Nodejs 的响应是 json,我正在尝试使用 Vue 在屏幕中显示它,如下所示
app.js (vue)
new Vue({
el: "#mdEditor",
data: {
content: '',
},
mounted: function() {
this.defaultPage();
},
methods: {
defaultPage: function() {
this.$http.get('/defaultPage')
.then((result) => {
this.$set(this, 'content', result.data.html);
console.log('result=', result);
}, (err) => {
console.log('error=', err);
});
}
}
});
HTML 文件
<div class="container" id="mdEditor">
<div class="col-sm-12">
<div class="panel panel-primary">
<div class="panel-body">
{{content}}
<!-- content of the md file goes here-->
</div>
</div>
</div>
但是内容(即 html 代码)打印为文本而不是 html。 提前感谢您的帮助
【问题讨论】:
标签: javascript html node.js vue.js