Vuex:Mutation常量类型


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

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM