<div id="app">
<h2>Todos:</h2>
<ol>
<li v-for="todo in todos">
<label>
<input v-model="todo" >
</label>
</li>
</ol></div>new Vue({
el: "#app",
data: {
todos: [1,2,3]
},
watch:{
todos: {
handler(newValue, oldValue) {
for (let i = 0; i < newValue.length; i++) {
if (oldValue[i] != newValue[i]) {
alert(newValue)
}
}
},
deep: true
}
}, methods: { toggle: function(index,e){ alert(e)
}
}
})demo:http://jsfiddle.net/9hmndL4x/点击预览 改变input里边的值没有触发watch
2 回答

冉冉说
TA贡献1877条经验 获得超1个赞
<li v-for="(todo, index) in todos"> <label> <input v-model="todos[index]" > </label></li>
添加回答
举报
0/150
提交
取消