用常量替代 Mutation 事件类型。可以方便大型项目的命名规范
export const INCREMENT = ‘increment‘
//1 导入 import {INCREMENT} from "./store/mutations-types"
//2 使用 //methods:{ addition(){ this.$store.commit(INCREMENT) }, subtraction(){ this.$store.commit(‘decrement‘) } }
//1导入 import * as myMutations from "@/store/mutations-types"
mutations:{ //方法 默认带state参数 [myMutations.INCREMENT](state){ state.counter++ }, decrement(state){ state.counter-- } },
原文:https://www.cnblogs.com/polax/p/13231466.html