在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 打開vue 通過儲存的狀態(tài)判斷是否要登錄怎么做?我做的總是登錄頁閃一下

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

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

用hbuilder打包了個app

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

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

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

怎么做才能 打開app的時候 直接到內(nèi)容頁 。像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: {

// 一定時間段內(nèi)打開APP直接進入到授權(quán)列表
enterList(){
  this.plusReady(function(){
      this.sign = plus.storage.getItem('sign');   //  獲取狀態(tài)
      if(this.sign){                              //  判斷有存儲狀態(tài)的話 就直接跳到 內(nèi)容頁,不再登錄
      this.$router.push({ name: "list" });    
    };
  }.bind(this))
},
// 一定時間段內(nèi)打開APP直接進入到授權(quán)列表
// 返回按鍵監(jiān)聽
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)聽

}
};
</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' // 注冊實名
import authorization from '@/components/authorization' // 授權(quán)頁面
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)容頁
},
{
  path: '/register',
  name: 'register',
  component: register
},
{
  path: '/authorization',
  name: 'authorization',
  component: authorization
},
{
  path: '/protocol',
  name: 'protocol',
  component: protocol
}

]
})

回答
編輯回答
替身

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

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

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

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

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

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

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

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

2018年6月23日 07:03