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-- } },