/*** 在 vuex 中 获取数据大多使用辅助方法** mapState* mapGetters* mapMutations 放在 methods 中 同步更改数据* mapActions 放在 methods 中 异步步更改数据** */// 全局辅助方法import { mapState, mapGetters, mapMutations,mapActions } from 'vuex';export default {computed: {// lesson() {// return this.$store.state.lesson// }// mapState 封装之后...mapState(['lesson','time']) ,// 获取 state 中的数据// lesson 更改名字 u// ...mapState({// u:state =>state.lesson// },'time') // 获取 state 中的数据// 拿取子模块 user 中的数据...mapState('user',['userName']),// mapGetters...mapGetters(['getName']),...mapGetters( 'user',['getUserName']),},methods: {...mapMutations(['changeTime']), // 仅仅处于函数还没执行// 同步更改子模块 user 中的数据...mapMutations('user',['changeUser']),// 异步更改数据...mapActions(['changeTime']),change () {// 同步 直接执行 changeTime 函数// 通过 commit 唤醒 mutations changeTime 提交 mutation 类型// this.$store.commit('changeTime', '20191029')// this.$store.commit('changeUser', '白茶清欢')// this.changeTime('20191029');// this.changeUser('白茶清欢');// mapActions 异步步更改数据// this.$store.dispatch('changeTime','20191212')this.changeTime('20191212');this.changeUser('白茶清欢');},}}
