v-if data comes out in rendering
it is theoretically possible to request an interface in the created method. I don't know how your code is written
routebeforenter why not? Where do you write your next?
I really can't v-if to learn about it.
vif judges that the data has been received and then renders
Synchronize loads data and assigns values one by one after the last request is successful.
ajax cannot do Synchronize. You need to introduce promise, recommendation to use the officially recommended axios
for example, request data with axios:
data(){
return{
data1:'',data2:'',data3:''
}
}
// methods:
var data1, data2, data3;
axios.get('/user?ID=12345')
.then(function (res){
data1 = res.data
})
.then(function (res){
data2 = res.data
})
.then(function (res){
//
data3 = res.data
this.data1 = data1
this.data2 = data2
this.data3 = data3
})
.catch(function (error) {
console.log(error);
});
beforeRouteEnter can definitely achieve your needs, and I think there is nothing wrong with your writing. If the position of the picture you said is obviously refreshed, you can try it by adding a loading in the hook, or press the img.onload method mentioned above, but this method is not recommended, because only one picture is easy to operate. If more than one picture is awkward, it is recommended to load it lazily.
body add a v-cloak