首页 > 其他 > 详细

Vuex:Mutation常量类型

时间:2020-07-03 17:37:47      阅读:126      评论:0      收藏:0      [点我收藏+]

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

 

 

 

Vuex:Mutation常量类型

原文:https://www.cnblogs.com/polax/p/13231466.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!