vuex模組中使用namespaced之後的引用方法
阿新 • • 發佈:2018-12-21
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
})
}