对父组件传进来的数组进行监听,发现数组的数值改变了,但是watch却没有监听到,代码如下:
export default {
...
props: {
reportTypeList: {
type: Array,
default() {
return []
}
}
},
watch: {
reportTypeList(newValue){
// 对新数据做处理
this.allData = _.clone(newData);
this.allData.sort(util.compare('report_type', 'ascending'));
}
}
...
}
开启 deep 属性,对数组进行 深层watch,代码如下:
watch: {
reportTypeList: {
handler(newData){
this.allData = _.clone(newData);
this.allData.sort(util.compare('report_type', 'ascending'));
},
immediate: true,
deep: true
}
},