在watch生命周期里 获取的this.serviceList 不是正常的数组。
我需要改变 serviceList.child 的checked 值,该如何做?
export default {
props: ["list"],
data() {
return {
serviceList: []
}
},
mounted() {
common.ajaxGet(common.api + "/service/categorys", {
pageSize: 10000
})
.then(data => {
if (data.code == 200) {
console.log("tip2 =>", data.data);
$.each(data.data, (i, iObj) => {
if (iObj.isEnabled) {
let services = {
id: iObj.id,
name: iObj.name,
child: []
}
if (iObj.servers.length > 0) {
$.each(iObj.servers, (j, jObj) => {
if (jObj.isEnabled) {
let temp = {
id: jObj.id,
name: jObj.name,
price: jObj.price,
categoryId: jObj.categoryId,
categoryName: iObj.name,
checked: false
}
services.child.push(temp);
}
});
}
this.serviceList.push(services);
}
});
}
});
},
watch: {
list(val) {
let idList = val.map(obj => obj.id);
console.log("idList", idList, this.serviceList);
//此处 this.serviceList 获取的不是数组,不知道如何循环
}
}
}

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证高级PHP讲师