1.直接使用
- state --> $store.state.模块名.数据项名
- getters --> $store.getters'**模块名**/属性名'
- mutations --> $store.commit('模块名/方法名', 其他参数)
- actions --> $store.dispatch('模块名/方法名', 其他参数)
2.借助辅助方法使用
1.import { mapXxxx, mapXxx } from 'vuex'
computed、methods: {
// ...mapState、...mapGetters放computed中;
// ...mapMutations、...mapActions放methods中;
...mapXxxx('模块名', '数据项\|方法'),
...mapXxxx('模块名', { 新的名字: 原来的名字 }),
}
2.组件中直接使用 属性 {``{ age }} 或 方法 @click="updateAge(2)"