1.取state的值(mapState)
1.import { mapState } from 'vuex'
2. computed: {
...mapState({
foodData: state => state.food_list,
table: state => state.table,
user: state => state.user
})
}
3.this.table
2.保存值(mapMutations )
注:setTable: (state, table) => {
state.table = table
},
1.import { mapMutations } from 'vuex'
2.methods: {
...mapMutations([
'setTable'
]),
}
3.this.setTable //无需定义
3.actions里面写事件(mapActions)
注:logOut ({ commit }) {
return new Promise((resolve) => {
this._vm.$post('/storeapp/login/loginout').then((res) => {
commit('foodList', '')
commit('setUser', '')
resolve()
}).catch(() => {
commit('foodList', '')
commit('setUser', '')
})
})
}
1.import { mapActions } from 'vuex'
2.methods: {
...mapActions({
logOutAction: 'logOut'
}),
}
3.this.logOutAction()
网友评论