mapMutation

120 阅读1分钟

利用mapMutations方法使用拓展运算符把mutations的方法解构在methods中

在this中也可以找到对应解构出来的方法*/

    /* 如果mutations中的方法名和methods中的同名了,可以采用对象的形式修改 */
    ...mapMutations({
      addfn:'ADD',
      delfn:'DEL'
    }),

类似于下面

 DEL:function(){...}, */
 addNum(){
   /* this.$store.commit('ADD',2) */
   /* this.ADD(2) */
   this.addfn(2);
 },
 delNum(){
   /* this.$store.commit('DEL',2) */
   /*  this.DEL(2) */
   this.delfn(2)
 },
 ADD(){
   console.log(2)
 },
 ```
 利用mapActions方法使用拓展运算符把actions的方法解构在methods中 
  在this中也可以找到对应解构出来的方法*/
 会在methods中解构成类似的形式
 addajax:function(){...},
 ...mapActions(['addajax']),
 如果actions中的方法名和methods中的同名了,可以采用对象的形式修改