0đź‘Ť
âś…
The reason you see null
in created
is because asynchronous action started in beforeCreate
is not complete yet.
If you really need result of the action to be complete in created you need to to this:
async created() {
await this.$store.dispatch('getWeather');
console.log(this.$store.getters.getWeatherInfo) // now the data is in store
}
If you don’t need data to be ready in created
it’s better to remove await
and write your component template using v-if
– “render this only if my getter is not null” …it will be not-null eventually (“sometime in the future”) and Vue will re-render your component…
Source:stackexchange.com