鍍金池/ 問(wèn)答/HTML/ 打開(kāi)vue 通過(guò)儲(chǔ)存的狀態(tài)判斷是否要登錄怎么做?我做的總是登錄頁(yè)閃一下

打開(kāi)vue 通過(guò)儲(chǔ)存的狀態(tài)判斷是否要登錄怎么做?我做的總是登錄頁(yè)閃一下

打開(kāi)vue 通過(guò)儲(chǔ)存的狀態(tài)判斷是否要登錄怎么做?我做的總是登錄頁(yè)閃一下

用hbuilder打包了個(gè)app

第一次打開(kāi)是登錄
登錄成功個(gè) 會(huì)儲(chǔ)存一個(gè)狀態(tài) (這個(gè)狀態(tài)存儲(chǔ)1天失效)
現(xiàn)在關(guān)閉APP

if 狀態(tài)有效 =》 下次打開(kāi)app =>直接跳到內(nèi)容 不用再登錄

現(xiàn)在問(wèn)題是 打開(kāi) app ,頁(yè)面會(huì)在登錄頁(yè)閃一下 ,馬上跳轉(zhuǎn)到內(nèi)容,看起來(lái)很怪

怎么做才能 打開(kāi)app的時(shí)候 直接到內(nèi)容頁(yè) 。像QQ一樣

============================================================

<template>
<div id="app">

<router-view/>

</div>
</template>

<script>
export default {
name: "App",
data(){

return {
  sign:'',    //狀態(tài)
}

},
created() {

this.exitApp();
this.enterList()

},
methods: {

// 一定時(shí)間段內(nèi)打開(kāi)APP直接進(jìn)入到授權(quán)列表
enterList(){
  this.plusReady(function(){
      this.sign = plus.storage.getItem('sign');   //  獲取狀態(tài)
      if(this.sign){                              //  判斷有存儲(chǔ)狀態(tài)的話 就直接跳到 內(nèi)容頁(yè),不再登錄
      this.$router.push({ name: "list" });    
    };
  }.bind(this))
},
// 一定時(shí)間段內(nèi)打開(kāi)APP直接進(jìn)入到授權(quán)列表
// 返回按鍵監(jiān)聽(tīng)
plusReady(callback) {
  if (window.plus) {
    callback();
  } else {
    document.addEventListener("plusready", callback);
  }
},
exitApp() {
  this.plusReady(
    function() {
      plus.key.addEventListener("backbutton", function() {
        console.log("按下返回按鍵");
        plus.runtime.quit()
        
      });
    }.bind(this)
  );
}
// 返回按鍵監(jiān)聽(tīng)

}
};
</script>

<style>

</style>

===================================

import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login' // 登錄
import list from '@/components/list' // 授權(quán)列表
import register from '@/components/register' // 注冊(cè)實(shí)名
import authorization from '@/components/authorization' // 授權(quán)頁(yè)面
import protocol from '@/components/protocol' // 協(xié)議類容

Vue.use(Router)

export default new Router({
routes: [

{
  path: '/',
  name: 'login',
  component: login       //  這里是登錄
},
{
  path: '/login',
  name: 'login',
  component: login       //  這里也是登錄
},
{
  path: '/list',
  name: 'list',
  component: list        //  內(nèi)容頁(yè)
},
{
  path: '/register',
  name: 'register',
  component: register
},
{
  path: '/authorization',
  name: 'authorization',
  component: authorization
},
{
  path: '/protocol',
  name: 'protocol',
  component: protocol
}

]
})

回答
編輯回答
替身

不要默認(rèn)顯示登錄頁(yè),先顯示空白頁(yè),判斷完登錄狀態(tài)再顯示登錄頁(yè)或者內(nèi)容頁(yè),就不會(huì)閃了

2017年10月20日 04:40
編輯回答
貓館

代碼格式太亂,沒(méi)看。
在路由里面做導(dǎo)航守衛(wèi),before里做判斷,有的話直接跳目標(biāo)頁(yè),沒(méi)有的話再繼續(xù)往登錄頁(yè)去。

2018年6月23日 03:06
編輯回答
凹凸曼

同樓上,代碼太亂,沒(méi)仔細(xì)看……

登錄頁(yè)先隱藏吧,判斷了登錄狀態(tài)再修改顯示屬性。

2017年8月26日 13:58
編輯回答
安若晴

在請(qǐng)求統(tǒng)一的響應(yīng)攔截器里面:如果后端返回狀態(tài)碼為未登錄的狀態(tài),router.push("/login")

2018年6月23日 07:03