1.创建对像
const state = {
// 存放字典集,以key为健存储
dictionaries: {
root: {},
page: {}
},
dictionary:'', //获取字典
// 缓存请求结果,以url|uri为健存储
allDictRequestCache: {}
}
2.mutations可以直接修改state存放方法
const mutations = {
SET_CACHE: (state, cache) => {
state.allDictRequestCache = cache
}
3.actions是用来触发mutations的它无法直接改变state,它可以包含异步操作,它只能通过store.dispatch触发*通过commit去执行mutations的方法
const actions = {
async pull (){}
}
export default {
namespaced: true, //此属性是避免module属性与其他的module属性导出的state等内含属性重复报错所加
state,
mutations,
actions
}
4. getters注册在全局的命名空间
this.$store.getters['ec/dict/dictionary']
const getters = {
dictionary (state) {}
}
Vue中this.$store.dispatch() 与 this.$store.commit()
1、commit: 同步操作
* this.$store.commit('方法名',值)【存储】
* this.$store.state.方法名【取值】
2、dispatch: 异步操作
* this.$store.dispatch('方法名',值)【存储】
* this.$store.getters.方法名【取值】
模板中vue中调用
import { mapActions, mapState } from "vuex";
...mapActions(["checkSatId"]),