[Vuejs]-Importing Vuex Plugins without defining a Store

4👍

You just need to mention it once in your store/index.js:

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import createPersistedState from 'vuex-persistedstate'
import posts from '~/store/posts.store'

....

export default new Vuex.Store({
  state:     { ... },
  mutations: { ... },
  actions: { ... }, 
  modules: { 
    posts,
    ... 
  },
  plugins: [createPersistedState()]
})

in your posts module:

const state = () => ({ ... })
const getters = { ... }
const mutations = { ... }
const actions = { ... }
export default { namespaced: true, state, getters, actions, mutations }    

that works for me.

Leave a comment