vuex模块中使用namespaced之后的引用方法

  • Post author:
  • Post category:vue


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

})

}



版权声明:本文为VVVZCS原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。