提交 af985bab authored 作者: 王鹏飞's avatar 王鹏飞

fix: 更新token状态

上级 43410085
...@@ -6,14 +6,12 @@ export default class Before { ...@@ -6,14 +6,12 @@ export default class Before {
async update(to, from, next) { async update(to, from, next) {
if (to.meta.requiredLogin) { if (to.meta.requiredLogin) {
const isLogin = const isLogin = store.state.isLogin || (await store.dispatch('checkLogin'))
store.state.isLogin || (await store.dispatch('checkLogin'))
if (isLogin) { if (isLogin) {
wx.miniProgram.postMessage({ data: { token: store.state.token } })
next() next()
} else { } else {
store.state.isWeapp store.state.isWeapp ? wx.miniProgram.redirectTo({ url: '/pages/login/index' }) : next('/login')
? wx.miniProgram.redirectTo({ url: '/pages/login/index' })
: next('/login')
} }
return return
} }
......
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import Cookies from 'js-cookie'
import { getUser, logout } from '@/api/account' import { getUser, logout } from '@/api/account'
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
...@@ -38,10 +40,12 @@ export default new Vuex.Store({ ...@@ -38,10 +40,12 @@ export default new Vuex.Store({
const isLogin = await getUser() const isLogin = await getUser()
.then(response => { .then(response => {
commit('setUser', response) commit('setUser', response)
commit('setToken', Cookies.get('TGC'))
return true return true
}) })
.catch(() => { .catch(() => {
commit('setUser', {}) commit('setUser', {})
commit('setToken', '')
return false return false
}) })
commit('setIsLogin', isLogin) commit('setIsLogin', isLogin)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论