Vue,修改v-for 中list的 item 一个属性 但是失败,没有渲染出来

页面代码:

但是奇怪的是 我点击按钮 进行全选操作时,选择框并没勾上,哪里有问题?

img

for="item in itemList" :label="item.name" :key="item.id" :disabled="item.disabled" :checked="item.checked">{{ item.name }}
 

JS代码:

 handleCheckedAllItem() {
      this.checkAll = !this.checkAll
      console.log(this.checkAll)
      for(let index=0;index<this.itemList.length;index++){
        let temp= this.itemList[index];
        temp.checked = this.checkAll
        this.itemList.splice(index, 1, temp); //替换数组中这个元素
      }
      console.log(this.itemList.length)
      console.log(this.itemList)
    }

结帖:

首先 没有按照官网那样来的,就是双向绑定的问题 v-for 不能检测到item 中数据的变化,需要用splice 进行替换元素, 说白了就是进栈出栈的问题,这样就行了,如果还是不行 那就像我一样 没有将元素写入group 的 v-model 中 ,注意绑定的v-for 元素的label

 for(let index=0;index<this.itemList.length;index++){
        let temp= this.itemList[index];
        temp.checked = this.checkAll
        this.itemList.splice(index, 1, temp); //替换数组中这个元素
        this.checkList.push(temp.name) //不能丢!!!!!!!!!!!
      }


不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^