1
我来自一个反应背景JSX,所以使用类似vue.js - V-HTML替代
var test = <div>i am a div</div>
设置一些事情的HTML是很常见的。我知道你可以使用V-HTML实现同样的事情,但不知道是否这是最好的/最安全的方式这样做给我下面的代码:
VUE组件
<template src="./templates/General.html"></template>
<script>
export default {
name: 'guide-general',
data: function() {
return {
guides: [
{
title: "first",
description: "First description"
},
{
title: "second",
description: "second description"
},
{
title: "third",
description: `<ul>
<li>
test
</li>
</ul>`
}
]
}
},
methods: {
}
}
</script>
<style scoped>
</style>
HTML模板
<article>
<div v-for="guide in guides">
<h4>{{ guide.title }}</h4>
<div v-html="guide.description">
</div>
</div>
</article>