如何在VueJS中的字符串内插变量

问题描述 投票:1回答:1

我想在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变量中的字符串

json vue.js httprequest string-interpolation
1个回答
0
投票
export default {
    data () {
      return {
        rawHtml: "<h1> This is some HTML </h1>",
      }
    },
    render(){
        return(
          <div>
            <div domPropsInnerHTML={this.rawHtml}> </div>
          </div>
        )
      }
}
© www.soinside.com 2019 - 2024. All rights reserved.