javascript - v-html 中的 Vue.js v-model

标签 javascript html vue.js vuejs2 vue-component

我想将 html 存储在变量中。示例:

data: function() {
  return {
    my_html: '<input type="text" v-model="data"'
  }
}

我想在数据中接收用户在字段中输入的值。但是这个连接不起作用 完整示例:

var test = new Vue({
  el: '#some_id',
  data: function() {
    return {
      data: '',
      my_html: '<input type="text" v-model="data" />'
    }
  },
  template: 
    '<div>
      <input type="text" v-model="data" />
      <input type="text" v-model="data" />
      <span v-html="my_html"></span>
    </div>'
});

在此示例中,前两个输入通常会与数据链接并相互链接,但第三个(span 内的那个)不会

最佳答案

根据 the official doc :

The contents of the span will be replaced with the value of the rawHtml property, interpreted as plain HTML - data bindings are ignored. Note that you cannot use v-html to compose template partials, because Vue is not a string-based templating engine. Instead, components are preferred as the fundamental unit for UI reuse and composition

有关更多详细信息,请尝试查看@RoyJ 的 answer

关于javascript - v-html 中的 Vue.js v-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53642874/

相关文章:

javascript - 自定义 JavaScript 作为 DOM 节点属性,在准备就绪时执行

循环后Javascript undefined variable

html - Bootstrap clearfix 问题

javascript - vm.handleClick 不是 vue.js 上的函数

javascript - .使用曲线制作动画

javascript - .on() 无法在 ajax 加载的页面上工作

javascript - 将数据传递给另一个组件

javascript - vue-cli 从组件构建一个库并导入它

javascript - 点击父元素时的JS函数,但点击子元素时返回false

javascript - 从页面顶部到底部隐藏一个div