vue数组绑定的input值发生变化时watch没有监听到?

<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


ibeautiful
浏览 1594回答 2
2回答

冉冉说

<li&nbsp;v-for="(todo,&nbsp;index)&nbsp;in&nbsp;todos"> &nbsp;&nbsp;<label> &nbsp;&nbsp;&nbsp;&nbsp;<input&nbsp;v-model="todos[index]"&nbsp;> &nbsp;&nbsp;</label></li>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Vue.js