1  作用

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

2 文件结构

Vuex:Mutation常量类型

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

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-09-17
  • 2021-12-06
  • 2021-06-09
  • 2021-08-23
  • 2021-10-16
猜你喜欢
  • 2022-12-23
  • 2023-04-04
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-08-01
相关资源
相似解决方案