有时候我们会通过异步请求来获取数据,此时我们直接通过this.data去赋值的话,会发现页面不能刷新dom,此时我们需要通过$set去给对象设置数据即可
that.$set(that.targetLevelTaskInfo, 'child2', res.data.data)
改之前:
this.targetLevelTaskInfo.child2 = res.data.data
改之后:
this.$ajax.get(url).then((res) => {
if (res.data.data) {
that.targetLevelTaskInfo = res.data.data
that.$ajax.get(global.api.targetSuperviseInfoUrl+'?fatherId='+that.param.id+"&targetLevel=2").then(res => {
if(res.data.status == 200){
that.$set(that.targetLevelTaskInfo, 'child2', res.data.data)
let child3Id = "";
res.data.data.forEach(item=>{
child3Id+=item.id+','
})
that.$ajax.get(global.api.targetSuperviseInfoUrl+'?fatherId='+child3Id+"&targetLevel=3").then(res => {
if(res.data.status == 200){
that.$set(that.targetLevelTaskInfo, 'child3', res.data.data)
let child4Id = "";
res.data.data.forEach(item=>{
child4Id+=item.id+','
})
that.$ajax.get(global.api.targetSuperviseInfoUrl+'?fatherId='+child4Id+"&targetLevel=4").then(res => {
if(res.data.status == 200){
that.$set(that.targetLevelTaskInfo, 'child4', res.data.data)
}
})
}
})
}
})
}
});