encountered a problem with using nextTick. The general logic in
is that the init () method takes data from the backend and stores it in this.addressList,. This data change will lead to the change of dom, but according to the principle of response, dom will not change immediately, it is an asynchronous process, so I use the nextTick method to wait for dom to change before getting a default address from it, but this still cannot be obtained. Is it selectedId or an empty string? Excuse me, do I misunderstand the use of nextTick?
mounted(){
this.init();
//??
this.$nextTick(function () {
this.addressList.forEach((item)=>{
if(item.isDefault){
this.selectedId=item.addressId;
}
})
})
},
methods:{
init(){
axios.get("/users/addressList").then((response)=>{
var res=response.data;
if(res.status==="0"){
this.addressList=res.result;
//
// this.addressList.forEach((item)=>{
// if(item.isDefault){
// this.selectedId=item.addressId;
// }
// })
}
})
},