I have a page which displays data fetched from server with axios.
I want to defer the page rendering until the axios request finishes.
The reason for this is that I have a prerendered version of the page. So while the axios request is still running, I would like to display the prerendered data instead of a blank screen (to prevent CLS issues).
This is what I have currently:
export default {
....
created() {
this.fetchData().then((returnedData) => this.personData = returnedData);
},
data() {
return {
personData: {
name: "",
},
};
},
methods: {
async fetchData() {
const response = await axios.get("api/persondata/");
return await response.data;
},
},
...
}
So basically what I want to do is to make the axios request "synchronous", or to somehow make the create() function wait until the request finishes.
An ideal scenario would be to prevent the rendering all-together and just display the prerendered page, in case the axios request fails.
Any ideas on how to do this?