vue.js

2018-12-10 v-model直接绑定v-for循环下的成

2018-12-10  本文已影响0人  土豆切成片
<div v-for="(item, index) in data" :key="index">
  // 直接绑定 v-for循环的item成员会报错
  <input v-model="item" />
</div>

You are binding v-model directly to a v-for iteration alias. This will not be able to modify the v-for source array because writing to the alias is like modifying a function local variable. Consider using an array o

报错内容为: 你将v-model直接绑定到v-for迭代别名。这将无法修改v-for源数组,因为写入别名就像修改函数局部变量一样。考虑使用一个对象数组并在对象属性上使用v-model。

<div v-for="(item, index) in data" :key="index">
  // 通过index, 绑定数组中对应项
  <input v-model="data[index]" />
</div>
上一篇 下一篇

猜你喜欢

热点阅读