在login页面设置token、获取token、移除token,同时有路由守卫


报错: [vuex] unknown mutation type: getToken 同时报错:TypeError: Cannot read properties of undefined (reading 'token')

原因:没有在store--index中引入user

这篇博客讨论了在 Vue.js 应用中使用 Vuex 管理登录状态时遇到的问题。具体表现为尝试从 store 中获取 token 时出现 'unknown mutation type: getToken' 的错误,以及 TypeError:无法读取未定义的 'token' 属性。错误的根本原因是未在 store 的 index 文件中引入 user 模块。解决方案包括正确导入并注册 user 模块,确保 mutation 类型定义正确,以及在全局路由守卫中适当地访问和处理 token。
在login页面设置token、获取token、移除token,同时有路由守卫


报错: [vuex] unknown mutation type: getToken 同时报错:TypeError: Cannot read properties of undefined (reading 'token')

原因:没有在store--index中引入user

4266