目录
// 用户状态
export default {
namespaced: true,
state: () => ({
// 个人用户信息
profile:{
id: '',
nickname: '',
avatar: '',
token: '',
mobile: ''
}
})
}
// 购物车状态
export default {
namespaced: true,
state: () => ({
list:[]
})
}
import { createStore } from 'vuex'
import user from './modules/user'
import cart from './modules/cart'
export default createStore({
modules: {
user,
cart
}
})
import { createStore } from 'vuex'
import createPersistedstate from 'vuex-persistedstate'
import user from './modules/user'
import cart from './modules/cart'
export default createStore({
modules: {
user,
cart
},
plugins: [
createPersistedstate({
key: 'erabbit-client-pc-store',
paths: ['user', 'cart']
})
]
})
import { createStore } from 'vuex'
import createPersistedstate from 'vuex-persistedstate'
import user from './modules/user'
import cart from './modules/cart'
// 引入包
import * as Cookies from 'js-cookie'
export default createStore({
state: {
},
mutations: {
},
actions: {
},
modules: {
user,
cart
},
// vuex + 本地储存 插件配置
// plugins: [
// createPersistedstate({
// key: 'erabbit-client-pc-store', // 本地储存 键值对的形式
// paths: ['user', 'cart']
// })
// ]
// 进行配置
plugins: [
createPersistedstate({
key: 'erabbit-client-pc-store', // 本地储存 键值对的形式
paths: ['user', 'cart'],
storage: {
getItem: key => Cookies.get(key),
setItem: (key, value) => Cookies.set(key, value, { expires: 7 }),
removeItem: key => Cookies.remove(key)
}
})
]
})