Vue wants to load all the data before rendering the page

my project uses vue,. My image link needs to be returned through the API. I don"t want the page to render the image and then refresh it. I tried sending requests in create and routebeforenter, but it didn"t seem to work. I was prompted to use lazy loading, but I remember lazy loading was for a placeholder, which was not what I wanted. I want a blank page to make the transition. After my data is loaded, the blank page disappears and the page is rendered directly.

Mar.20,2021

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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b1b5-2b9e5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b1b5-2b9e5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?