0
入力で何かをタイプで変更することはできません。 入力を観察して子供に影響を与える方法。 と名前がそれぞれの子のためにvue2どのように追加して、変更の要素を配列で観察しますか?
jsファイルがある場合を確認します。
$(function() {
var person = {
name: '',
children: ['Please enter a name']
}
var vm = new Vue({
el: "#example",
data: person,
methods: {
addChild: function (index) {
this.children.splice(index+1, 0, ""); //
},
removeChild: function (index) {
this.children.splice(index , 1)
},
getData: function() {
console.log(this.children);
}
}
})
})
HTML部分:
<ul >
<li v-for="(child,index) in children">
the child at <span>{{ index }}</span> is <span >{{ child }}</span>
<input v-model = "child">
<button @click="addChild(index)">newChild</button>
<button v-on:click="removeChild(index)">X</button>
</li>
</ul>
<button v-on:click="getData">watch data</button>
<div>{{ $data | json }} </div>
</div>
ありがとうございます。オブジェクトのarrrayの代わりに['child1'、 'child2']のような項目の配列を使用できますか? –
なぜ表示されないのですか。 – PatrickSteele
インデックスは機能しますが、入力がデータに影響を与えることはありません。理由はありません。 –