持久化插件
1、安装插件
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import Login from './login'
Vue.use(Vuex)
export default new Vuex.Store({
plugins: [createPersistedState()],
modules: {
Login
}
})
2、模块化使用
const Login = {
namespaced: true,
state: {
func: {}
},
mutations: {
saveFunc (state, data) {
state.func = data
}
},
actions: {
saveActionFunc ({ commit }, data) {
return new Promise((resolve, reject) => {
const funcObj = {
123456: true,
300100: true,
300101: true,
300102: true,
300106: true
}
commit('saveFunc', funcObj)
resolve(funcObj)
})
}
}
}
export default Login
3、页面中使用
computed: {
...mapState('Login', ['func'])
},
mounted () {
console.log(this.func, 'this.func in store')
},
methods: {
...mapActions('Login', ['saveActionFunc']),
handelLogin (formName) {
this.saveActionFunc()
}
}
vuex 插件地址
www.extfans.com/web-develop…