The state of my application seems to load AFTER my components get loaded, so my thought was to watch for the state-getter. But how do I watch a Vuex getter in the composition API?
My state & getter:
state: () => ({
companies: [],
}),
getters: {
getAvailableCompanies(state) {
return state.companies
}
},
[...]
}
In my module, I import the store:
import { store } from '@/store/store.js'
And get the value of the getter in the setup() function of my component:
const companies = ref(store.getters["companies/getAvailableCompanies"])
console.log("companies", companies)
Now I am trying to watch for changes (also in setup()), once the state is populated:
watch(
companies, (curr, old) => {
console.log(curr, old)
}
)
Unfortunately, companies.value
never changes and stays undefined