第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

刷新頁(yè)面后為什么router.beforeEach中state的為空?

刷新頁(yè)面后為什么router.beforeEach中state的為空?

largeQ 2018-09-03 12:11:02
刷新頁(yè)面后vuex從sessionStorage獲取,為什么router.beforeEach中state的為空?vuex:const state = {  state: {     token: sessionStorage.getItem('token') || '',   }, }router:router.beforeEach(function(to, from, next) {   console.log(to.meta.auth,store.state.token,to.path);   if (to.meta.auth && !store.state.token && to.path !== '/login') {     return next({       path: '/login',       query: {redirect: to.fullPath}     })   }   next(); });在用戶登陸后刷新頁(yè)面,為什么beforeEach里store.state.token為空?因?yàn)槲野裺tore寫成了state...QAQ每天都在問(wèn)傻逼問(wèn)題
查看完整描述

1 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊

const store = { // 這里是 store ?

  state: {

    token: sessionStorage.getItem('token') || '',

  },

}

初始化 store 實(shí)例時(shí),如果沒(méi)登錄 token 應(yīng)該是空的,之后如果登錄,sessionStorage 保存到 token 后,state.token 也不會(huì)再改變了,因?yàn)闆](méi)有 mutation 去觸發(fā)重新獲取


查看完整回答
反對(duì) 回復(fù) 2018-09-09
  • 1 回答
  • 0 關(guān)注
  • 1834 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)