-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Dispatch' undefined when inside new Nuxt fetch() #47
Comments
This happens if you declare the plugin like in module.exports = {
...,
plugins: [
...,
{ src: '~/plugins/vuex-cache.js', ssr: false },
]
};
if (process.browser)
await this.$store.cache.dispatch('getUser');
else
await this.$store.dispatch('getUser'); |
Perhaps then there would be an opportunity to add a hook inside vuex-cache to check for |
I don't think so, vuex-cache can be executed without window because just depends on Vuex, Promise and Map. You can change declaration of the plugin in nuxt.config to allow vuex-cache in SSR too. It may fix the problem. module.exports = {
...,
plugins: [
...,
'~/plugins/vuex-cache.js', // instead of { src: '~/plugins/vuex-cache.js', ssr: false }
]
}; |
It's not fixing problem, it turns out just an empty store |
In Nuxt 2.12+, there's a new
fetch()
method.Example:
Results in:
My
vuex-cache.js
in~/plugins
:I assume it's just because it is attempting to dispatch server-side but
vuex-cache
hasn't attached itself yet correctly to the$store
instance.Not sure if there's a solution to ensure that all dispatches server-side bypass the cache, and all client-side navigations include the cache action - barring doing twice the dispatch calls wrapped within
if (process.browser) {
checks?The text was updated successfully, but these errors were encountered: