【掌握vuex的高阶用法,复习用】
在使用module 模块化的时候 易出现命名冲突的情况,这时候就需要使用vuex的命名空间
如何使用?
1、在该模块中 添加 namespaced : true
modules: {
goods: {
namespaced: true,
state: {
},
getters: {
},
mutations: {
},
actions: {
}
}
}
2、在页面使用
获取state中的数值 :{ { this.$store.state.goods.goodsNum } }
获取getters中的值 :{ { this.$store.getters["goods/changeNum"] } }
使用mutations中的方法 :this . $store . commit ("goods/addNum");
使用actions中的方法 : this . $store . dispatch ("goods/reduceNum");