我想在VueJS中插入一个包含变量和html的字符串。 Vue中有任何选项吗?
component.vue
<template>
<div v-html="test1"></div>
</template>
<script>
export default {
name: 'component',
data() {
return {
test: "test interpolation",
test1: " <p> some text {{ test }} </p>",
};
},
}
</script>
在Http请求后,从Json文件中加载了test1变量中的字符串
export default {
data () {
return {
rawHtml: "<h1> This is some HTML </h1>",
}
},
render(){
return(
<div>
<div domPropsInnerHTML={this.rawHtml}> </div>
</div>
)
}
}