vuex模塊中使用namespaced之後的引用方法

store->index.js

export default new Vuex.Store({
  state,
  mutations,
  actions,
  modules: {
    user
  }
})
 

user.js

const state = {
  userName: 'ReSword'
}
const mutations = {
  //
}
const actions = {
  //
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
 

xxxx組件

import { createNamespacedHelpers } from 'vuex'

computed: {

const { mapState } = createNamespacedHelpers('user')

        ...mapState({
            userName: state => state.userName
        })

}

或者

import { mapState } from 'vuex'

computed: {

...mapState('user', {
            userName: state => state.userName
        })

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章