namespaced属性用于解决不同模块的命名冲突问题
在业务模块中,导出时使用namespaced: true
export default {
namespaced: true,
state,
mutations,
actions,
};
用法:
①在getters.js中
state.user.name就是state.名称.存储字段
const getters = {
...
name: state => state.user.name,
};
export default getters;
②在普通组件中
dispatch和commit需要带名称
this.$store
.dispatch("user/login", this.loginForm)
.then(() => {
...
})
.catch(() => {
this.loading = false;
});