v-model directives cannot update the iteration variable item itself

v-model 无法更新迭代变量item 本身

1
2
3
4
5
6
7
const categorys = [1, 2, 3 ,4]
<div
v-for="(item, index) in categorys"
:key="index"
>
<input v-model="item" />
</div>

这样写会报 Module Error

另外声明变量去替代item

这样写就可以了

1
2
3
4
5
6
7
8
const categorys = [1, 2, 3 ,4]
const categorysOther = this.categorys
<div
v-for="(item, index) in categorys"
:key="index"
>
<input v-model="categorysOther[index]" />
</div>
# ,

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×