Complete the code to import the Vuex plugin for persisting state.
import createPersistedState from '[1]';
The correct package to import for persisting Vuex store state is vuex-persistedstate.
Complete the code to add the persisted state plugin to the Vuex store.
const store = createStore({
plugins: [[1]()],
state() {
return { count: 0 };
}
});The plugin function imported is called createPersistedState, which needs to be called to create the plugin instance.
Fix the error in the code to correctly persist only the 'user' module state.
const store = createStore({
modules: {
user: userModule
},
plugins: [createPersistedState({
paths: [[1]]
})]
});The paths option expects an array of strings representing module names. So the module name 'user' must be a string.
Fill both blanks to configure the persisted state to use sessionStorage and only save 'settings' module.
const store = createStore({
modules: {
settings: settingsModule
},
plugins: [createPersistedState({
storage: window.[1],
paths: [[2]]
})]
});To use session storage, set storage to window.sessionStorage. To persist only the 'settings' module, include its name as a string in paths.
Fill all three blanks to create a persisted state plugin that uses localStorage, saves 'cart' and 'user' modules, and sets a custom key 'myAppStore'.
const store = createStore({
modules: {
cart: cartModule,
user: userModule
},
plugins: [createPersistedState({
storage: window.[1],
paths: [[2], [3]],
key: 'myAppStore'
})]
});Use window.localStorage for storage. The paths array should include the module names as strings: 'cart' and 'user'. The key option sets the storage key, here 'myAppStore'.