0👍
Usually the mounted
hook of child component is called before the mounted
of parent component.
If you try to console.log
on both mounted
hook you will see the order of execution (but I’m still not sure why your store.getters.getHostUrl
is set).
So you need a watcher to run your code after your store has value.
Example code:
...
computed: { // or use another getters
url () {
if (!store.getters.getHostUrl || !store.getters.getApiKey) return
return `${store.getters.getHostUrl}/api/${store.getters.getApiKey}/countryCodes`
}
},
watch: {
url (value) {
...
}
}
...
0👍
So…. there were two ways of solving this….. thank you to both comments.
-
Switch my mounted in the main.js to created- the diagram above explains why… as well as the nice article.
-
add "await store.getters.getApiKey"
Source:stackexchange.com