实现深复制代码片段:
<li v-for="(items, i) in shopFileListData" @click="onCheckBox(items)" :key="items.shopFileId" :class="{'li-checked': liChecked(items)}">
<div class="source-file" style="width: 200px;">
.....
</div>
</li>
export default {
data() {
return {
shopFileListData:[],
fileList:[],
}
},
computed:{
allChecked:{
get: function() {
return this.checkedCount == this.shopFileListData.length;
},
set: function (value) {
if(value){
this.checked = this.shopFileListData.map((items) => {
this.fileList.push(items);
return items.shopFileId+'';
})
//this.fileList = this.shopFileListData;
console.log(JSON.stringify(this.fileList))
}else {
this.checked = [];
this.fileList = []
}
}
},
checkedCount: {
get: function() {
return this.checked.length;
}
},
},
}
this.shopFileListData为json数组,通过map()把里面的items,push到this.fileList中,这样进行了深复制。
注:
用ES6函数箭头,才使this.fileList的this指向全局vue对象;
items.shopFileId+''是为了把items.shopFileId转化成字符串类型;