小白兔晒黑了

导航

 

1  作用

用常量替代 Mutation 事件类型。可以方便大型项目的命名规范

2 文件结构

3 代码

3.1 src\store\mutations-types.js

export const INCREMENT = 'increment'

3.2 src\App.vue

//1 导入  
import {INCREMENT} from "./store/mutations-types"
//2 使用methods:{
      addition(){
        this.$store.commit(INCREMENT)
      },
      subtraction(){
        this.$store.commit('decrement')
      }
    }

3.3 src\store\index.js

//1导入 
import * as myMutations  from "@/store/mutations-types"
mutations:{
    //方法 默认带state参数
    [myMutations.INCREMENT](state){
      state.counter++
    },
    decrement(state){
      state.counter--
    }
  },

 

 

 

posted on 2020-07-03 17:08  小白兔晒黑了  阅读(869)  评论(0编辑  收藏  举报