[Vuejs]-Component rendered before correct prop data is passed in from another component

0👍

You can wait for the loadPost action to be completed in beforeCreated(), then the component won’t be created before the API responds. But be aware that this is not the best practice since the user won’t see anything before the API returns a response.

Example:

<template>
    <PostForm v-bind:key="fetchPost" />
</template>


<script>
async beforeCreate() {
    await this.$store.dispatch('loadPost');
}
computed: 
    fetchPost() {
        return this.$store.getters.getPost;
    }

</script>

Leave a comment