A few major steps for newbies using vuex

The first step is to create a store file to create these js files

In the second step, we need to send the mask_layer in the App file to another file. Note: introduce mapGetters, 

Also, I will call here first, and I will call directly next time.

 import {mapGetters} from 'vuex'

    computed: {
      ...mapGetters(['showZZC']),
    },
    watch:{
      ...mapGetters(['showZZC']),
      showZZC(val){
        this.mask_layer = val
      },

The third step: write like this in ues.js

const user = {
  state: {
    showZZC:false
  },

  mutations: {
    //修改state里面的enterpriseSelectEvent
    changeZZC: (state, val) => {
      state.showZZC= val
    },
  },

  actions: {
  }
}
export default user

Step 4: Inside getter.js

const getters = {
  showZZC:state => state.user.showZZC,//这里的user是你的modules里面具体文件名字比如user.js
}
export default getters

Step 5: In the index 

import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import getters from './getters'

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    user
  },
  getters
})

export default store

Step 6: After writing the created js files, you need to write in the received file

First quote it in main.js, if it is introduced in the current page, there will be no this when calling   : 1, 

// import store  from '@/store'

在mian.js中  还得加一个  Vue.prototype.$store = store 

然后全局都可以用,this.$store

Reuse: 2,

// this.$store.commit('showZZC', true)

This complete step is over! ! ! ! !

 

 

Guess you like

Origin blog.csdn.net/weixin_44727080/article/details/115001927