import PersistedState from '../PersistedState' // initial state const state = { total_amount:PersistedState.getStorage('homecart','total_amount', 0), // 总量 total_price:PersistedState.getStorage('homecart','total_price', 0.00), // 总价 cartGoods: PersistedState.getStorage('homecart','cartGoods', []) // 购物车中选中的商品 } // mutations const mutations = { // 计算购物车总量和总价 calculationAmount (state, amount) { state.total_amount = amount PersistedState.setStorage('homecart',state) }, calculationPrice (state, price) { state.total_price = price PersistedState.setStorage('homecart',state) }, saveSelectedCartGoods (state, payload) { state.cartGoods = payload.cartGoods PersistedState.setStorage('homecart',state) }, clearSelectedCartGoods (state) { state.cartGoods = [] PersistedState.setStorage('homecart',state) } } export default { state, mutations }