[英]Vue.js v-model inside v-html
I want to store html inside variable.我想将 html 存储在变量中。 Example:
例子:
data: function() {
return {
my_html: '<input type="text" v-model="data"'
}
}
And I want to receive in data the value that user enters in the field.我想在数据中接收用户在字段中输入的值。 But this connection does not work Full example:
但是这个连接不起作用完整的例子:
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>'
});
In this example, the first two inputs will normally link with data and with each other, but the third (the one inside span) won't在此示例中,前两个输入通常会与数据链接并彼此链接,但第三个(跨度内的那个)不会
According to 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.span 的内容将替换为
rawHtml
属性的值,解释为纯 HTML - 数据绑定被忽略。 Note that you cannot use v-html to compose template partials, because Vue is not a string-based templating engine.请注意,您不能使用 v-html 来编写模板部分,因为 Vue 不是基于字符串的模板引擎。 Instead, components are preferred as the fundamental unit for UI reuse and composition
相反,组件更适合作为 UI 重用和组合的基本单元
for more details try to check @RoyJ's answer有关更多详细信息,请尝试查看@RoyJ 的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.