admin管理员组文章数量:1402321
I want to store html inside variable. 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
I want to store html inside variable. 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
Share Improve this question edited Aug 21, 2019 at 17:03 Boussadjra Brahim 1 asked Dec 6, 2018 at 0:31 JarofjamJarofjam 431 silver badge3 bronze badges 2-
2
You'll need a dynamic ponent instead of
v-html
. See this answer – Roy J Commented Dec 6, 2018 at 0:45 - Possible duplicate of Dynamically replaced text string with Vue ponent – Daniel Beck Commented Feb 2, 2019 at 15:57
1 Answer
Reset to default 5According 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. Note that you cannot use v-html to pose template partials, because Vue is not a string-based templating engine. Instead, ponents are preferred as the fundamental unit for UI reuse and position
for more details try to check @RoyJ's answer
本文标签: javascriptVuejs vmodel inside vhtmlStack Overflow
版权声明:本文标题:javascript - Vue.js v-model inside v-html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744325094a2600687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论