vuex 的模块Module中如何调用 actions 中的方法
模块globalOrgIdStore.js
const globalOrgIdStore = {
namespaced: true,
state: {
globalOrgId: null,
orgType: 1, // 判断是否为公司端 0-站点;1-公司
},
getters: {},
mutations: {
getGlobalOrgId(state, data) {
state.globalOrgId = data
},
getOrgType(state, data) {
state.orgType = data
}
},
actions: {
setGlobalOrgId(context) {
context.commit('getGlobalOrgId')
},
setOrgType(context) {
context.commit('getOrgType')
}
}
}
export default globalOrgIdStore
1、不使用辅助函数 mapActions 情况下
this.$store.dispatch('globalOrgIdStore/setOrgType', data.orgType)
this.$store.dispatch('globalOrgIdStore/setGlobalOrgId', data.orgId)
2、适用辅助函数 mapActions 情况下
import { mapActions } from 'vuex'
methods: {
...mapActions('mapActions ',['setGlobalOrgId', 'setOrgType'])
fun(){
this.setOrgType(data.orgType)
}
}
本文介绍了在Vuex的模块中如何在两种场景下调用actions的方法:一是不使用辅助函数mapActions直接通过`this.$store.dispatch`;二是使用mapActions导入并简化action调用。

1017

被折叠的 条评论
为什么被折叠?



