vuex模块化使用

module/user.js代码

```

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const state = {

 liu:'jingna',

 wei:['yu','ning']

}

const mutations = {

 changeName(state,res){

     state.liu = res

 }

}

const actions = {

 changeNameA(context){

     context.commit('changeName','南京')

 }

}

export default {

 state,mutations,actions

}

```

index.js代码

```

```

import Vue from 'vue'

import Vuex from 'vuex'

import user from "./module/user"

Vue.use(Vuex)

export default new Vuex.Store({

 modules:{

user,

 },

  state: {

        count:7777

  },

  mutations: {

    change(state, value){

      // eslint-disable-next-line no-console

      console.log(value)

      // eslint-disable-next-line no-undef

      state.count=value

    },

  },

  actions: {

  changevalue(context,params){

    context.commit("change",params.count)

  }

  }

})

vue组件中使用

``

`

```

你可能感兴趣的:(vuex模块化使用)