登录页面→ Vuex => action ** dispatch → 跳转到主页面
↓ ↑
调用登录接口Commit ↑ resolve
↓ ↑
修改token的状态---------------↑
配置store/modules/user.js
// 状态
const state = {
token: null//设置tokenD的共享的状态
}
// 修改状态
const mutations = {}
// 执行异步
const actions = {}
export default {
namespaced: true,
state,
mutations,
actions
}
token不都是通过登录才能获取的,可以将token存到本地缓存中,封装好token的转态 获取token 设置token 删除token的方法 方便调用
import Cookies from 'js-cookie'
const TokenKey = 'xxxx-xxxxtoken' // 设定一个独一无二的key
export function getToken() {
return Cookies.get(Toke