这四种方法是简化vuex中代码
略
import {mapState,mapGetters,mapActions,mapMutations} from 'vuex'
//引入
computed:{
...mapState({:''})or...mapState(['']),//都有两种写法
...mapGetters({:''})
}//这两种是获取this.$store.state和this.$store.state.getters上面数据简化
methods:{
...mapActions({:''}),
...mapMutations({:''})
}//这是dispatch,commit逻辑过程的简化
//es6语法{...{}}
//参数写在绑定事件的方法中
详
computed:{
// game(){
// return this.$store.state.game
// },
// company(){
// return this.$store.state.company
// },
// bignum(){
// return this.$store.getters.bignum
// }//原始写法
// -----------------------------------
// ...mapState({game:'game',company:'company'}),//对象写法
...mapState(['game','company','name']),//数组写法
// ...mapGetters({bignum:'bignum'})
...mapGetters(['bignum'])
},
methods:{
// add(){
// this.$store.commit('ADDMSG',this.msg)
// // this.$store.dispatch('addmsg',this.msg)
// },
// reduce(){
// this.$store.dispatch('reduecmsg',this.msg)
// console.log(this.$store)
// },
// ifadd(){
// this.$store.dispatch('ifaddmsg',this.msg)
// },
// letteradd(){
// this.$store.dispatch('letteraddmsg',this.msg)
// },//原始写法
// -----------------------------------------
// ...mapActions(['reduecmsg','ifaddmsg','letteraddmsg']),//数组写法
...mapActions({reduce:'reduecmsg',ifadd:'ifaddmsg',letteradd:'letteraddmsg'}),//对象写法
// ...mapMutations(['ADDMSG'])
...mapMutations({add:'ADDMSG'})