最近在学习vue,遇到了这样一个问题.
this.bussno值的改变无法及时触发watch监听,只有在方法执行完,才会监听到最后一次值的改变,想不清楚是为什么.
赋值方法如下
for(let i=0;i<fileList.length;i++){
this.flag =i;
let saveData =new Object();
let fileType = fileList[i].type;
let arrayType = fileType.split("/");
if(arrayType.length > 1 && arrayType[0] == "image") {
saveData.imgfileflag = "1";
}else {
saveData.imgfileflag = "0";
}
let subStr =fileList[i].webkitRelativePath.split("/");
//承保or理赔
if(system =="Claim"){
saveData.typepath = fileList[i].webkitRelativePath;
this.bussno=subStr[2];
}else if(system =="Prpall"){
saveData.typepath= "";
let index =fileList[i].name.indexOf(".");
this.bussno=fileList[i].name.substring(0,index);
}
watch监听
watch:{
bussno:{
handler(newVal,oldVal){
console.log(newVal);
//最大号,
let that =this;
that.bussnoList.push(newVal);
if(that.system =="Claim"){
getAction(that.url.maxNo,{systemCode:that.system,bussNo:newVal}).then(res=>{
debugger;
if(res.success){
that.maxNo=res.result;
}else{
that.$message.error(res.message)
}
});
}
}
},
immediate: true,
},
求大佬解答!