Closed azulkipli closed 5 years ago
This wont work.
export const actions = {
...,
async doLogin({ cache, commit }) {
// ...
cache({timeout: 60000}).dispatch('showAlert', alertMsg)
},
};
There's no cache property on context (that object you're destructuring) because Vuex don't allow plugins to change the action context.
You have to use an action enhancer, and we named export cacheAction
function to handle it.
import { cacheAction } from 'vuex-cache';
export const actions = {
...,
// It receives a function declaration to allow `this` usage.
doLogin: cacheAction(async function ({ cache, commit }) {
// ...
cache.dispatch('showAlert', alertMsg, {timeout: 60000})
}),
};
In this 2.x.x version you can find some issues related to cache scope used in cacheAction, right now I'm working to release version 3.0.0 that will fix this issue and others.
Until then (will be soon) you can also import your store instance and use it's cache property instead.
import store from '../store';
export const actions = {
...,
async doLogin({ commit }) {
// ...
store.cache.dispatch('showAlert', alertMsg, {timeout: 60000})
},
};
Sorry, I forgot that Nuxt.js don't let you use store directly.
These issues related to cacheAction
don't happen if you use cached dispatch action outside your action context.
Have you tested with cacheAction
?
in previous project I've never call cache inside vuex actions, I call cache only on nuxt pages..
Maybe I will try on another project
Hi, thank you for creating this plugin.
I made vuex-cache as plugin on NuxtJS and successfully call it on pages as mention in documentation , call
store.cache.dispatch
infetch
method to initiate cache of ajax call.I think I need to call
cache
on store module actions,I have this sample store module on NuxtJS
How I can call
cache
on store module itself ?