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