The data that has been looped out by vue has been changed by clicking on the event, but the page data has not been updated.

 <div class="condition" :style="{background: item.collectColor}" v-for="(item,index) in myCollectList" :key="item.id"
             @click="selectMyCollectList(item,index)">
          <span>{{item.collectTitleName}}</span><i class="el-icon-check"  v-show="item.selected"></i>
        </div>
        
        
        selectMyCollectList(item,index) {
        item.selected = !item.selected;
        }
        
       
       
   
Feb.28,2021

set it to responsive data first

for (let i = 0; i < _this.myCollectList.length; iPP) {
              _this.$set(_this.myCollectList[i], 'selected', false)
            }
        

the data can be changed at this time, and the view will change

 selectMyCollectList(item,index) {
    item.selected = !item.selected;
    }
    

this.$set 

this.$set(item, 'selected', !item.selected)

:key="index"

key is the

of the index in the array bound to your loop.
  selectMyCollectList(item,index) {
        item.selected = !item.selected;
        }

there is no problem with this method, you can try to print to the page to see the data changes, there should be a problem elsewhere.

 <span>{{item.selected}}</span><i class="el-icon-check"  v-show="item.selected"></i>

Click to change the data, and you have to change the data in data. This method is changed as follows:

selectMyCollectList(item,index) {
    this.myCollectList[index]['selected']=!this.myCollectList[index]['selected'];
}

is the subject of the old version of vue? I also encountered this problem in my recent interview, but my page data is updated in real time, and I don't know why I ran through my project with the subject's code.

Menu