LimitAPI (searchData, page) {//asynchronous data acquisition
The return of new Promise ((resolve, reject)=& gt; {
Let the results={}, pagination={};
This. $API. GetMicroLimits (searchData). Then (res=& gt; {
Results=res. Items. The map (d=& gt; {
Return {
Key:, dc ode,
Code:, dc ode,
MicroService: d.m icroServiceName,
Description: d.d escription,
Status: da ctive,
Loading: false,
}
});
Pagination=this. $store. State. Pagination (page, res. ItemSize);
Resolve ({//returns the asynchronous here
Results: the results,
Pagination: pagination
});
}). The catch (err=& gt; {
This. $message. Error (err);
Reject (null);
})
});
}
value function called API, assigned to an object
.
Enclosing limitAPI (data page). Then (res=& gt; {
The console. The log (res. Data);//print data right here, to obtain the latest data
Enclosing currMicro={
//resolve the assignment writing object
Data: res. Results,
Pagination: res. Pagination,
. This. MslimitSearchObj. Record,
Loading: false
};
The console. The log (enclosing currMicro. Data);//data not update here
}). The catch (err=& gt; {
});
.
When the object to resolve assignment write to can be found, load data for the first time, the object was successfully assignment, currMicro data to get the complete data ;
But when calling the API values again, found resolve object assignment res print data is get latest data, but the assign values to the currMicro object, the object currMicro data printed is the data before the ,
after analysis, I guess is js compilation process problems, so I do the changes on assignment code,
.
Enclosing limitAPI (data page). Then (res=& gt; {
The console. The log (res. Data);//print data right here, to obtain the latest data
Enclosing currMicro={
. This. MslimitSearchObj. Record,
Loading: false
};
//the code written to resolve assignment objects
This. CurrMicro. Data=https://bbs.csdn.net/topics/res.results;
This. CurrMicro. Pagination=res. Pagination;
The console. The log (enclosing currMicro. Data);//the data updated successfully
}). The catch (err=& gt; {
});
.
The test again, currMicro object data updated successfully,
The difference between two js object attribute initialization method is different, but I didn't find the principle of the two methods of initialization
in this request bloggers to solve or discuss!
CodePudding user response:
See you this should be a vue, vue deep data changes to monitor need to add the deep in the corresponding attribute of the watch: true attribute,CodePudding user response: