2
當試圖創建動態輸入元素我得到一個模板編譯錯誤是這樣的:Vue2:V模型不支持動態輸入類型
V模型不支持動態輸入類型。改用v-if分支 代替。
https://jsfiddle.net/u8ncfdvn/
HTML
<div id="app">
<sr-el :persons="personsFoo" name="foo" type="number"></sr-el>
<br>
<sr-el :persons="personsBar" name="bar" type="text"></sr-el>
</div>
JS
Vue.component('sr-el', {
template: `
<span>
<input :type="type" :name="name" :id="name" v-model="inputVal" :class="{invalid: !persons}">
Here's the bound {{ name }} input value: {{ inputVal }}
</span>
`,
props: ['type', 'name', 'persons'],
data() {
return {
inputVal: this.persons,
}
}
})
new Vue({
el: '#app',
data() {
return {
personsFoo: 1,
personsBar: 2,
}
}
})
嗯,不是真的性感 – Mike
不,這不是。更大的問題是:爲什麼你需要一個基本上只是模仿'input'標籤功能的組件? – thanksd
我希望能夠管理不同表單元素的存在,驗證和配置。 – Mike