溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue 路由嵌套高亮問題的解決方法

發(fā)布時間:2020-10-25 20:24:45 來源:腳本之家 閱讀:209 作者:土豆兒哥 欄目:web開發(fā)

正常路由嵌套是沒有問題的,但是如果你已經(jīng)在當(dāng)前主路由頁面了,然后再次點擊主路由就會出現(xiàn)頁面數(shù)據(jù)空白的情況

看代碼:

//主路由通過v-for循環(huán)出來
<div class="list-group">
  <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" v-on:click="doNothing" class="list-group-item" v-if="getPages.length != 0">數(shù)據(jù)統(tǒng)計</a>
  <router-link v-for="page in getPages" class="list-group-item" :to="page.pageUrl">{{page.pageName}}</router-link>
</div>
//次路由通過URL拼接的方式導(dǎo)航到子路由頁面
<div class="panel-body tabs-wrap">
   <!--navtabbar begin-->
   <ul class="nav nav-tabs" v-if="isTencentPerson()">
      <router-link :to="{ name: 'statistics1',params:{showPanel:false} }" tag="li" role="presentation"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >統(tǒng)計1</a></router-link>
      <router-link :to="{ name: 'statistics2' ,params:{showPanel:false}}" tag="li" role="presentation"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >統(tǒng)計2</a></router-link> 
      <router-link :to="{ name: 'statistics3' ,params:{showPanel:false}}" tag="li" role="presentation"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >統(tǒng)計3</a></router-link> 
   </ul> 
   <!--navtabbar end--> 
   <!--內(nèi)容 begin-->
   <router-view></router-view>
</div>

子路由JS:

exprot default{  
     mounted() {
      this.routerHop();
    },
    updated() {
      //當(dāng)前頁再次點擊主路由時重新判斷跳轉(zhuǎn)
      var url = this.$route.path;
      if (url === "/statistics/dataStatistics") {
        this.routerHop();
      }
    },
    methods: {
      //權(quán)限判斷
      isPerson() {
        let user = this.$store.state.user.userInfo;
        if (user.userType == 1) {
          return true
        }
        return false;
      },
      routerHop(){
        // 客戶賬號登錄只顯示錯誤統(tǒng)計分析頁面
        if(this.isPerson() === false){
          return router.push({name: 'statistics1', params: {showPanel: false}});
        }
        router.push({name: 'statistics3', params: {showPanel: false}}); },
       }
    }
}

因為已經(jīng)在當(dāng)前子路由頁面,當(dāng)再次點擊主路由導(dǎo)航時,無法觸發(fā)mounted鉤子。通過updated這個鉤子函數(shù)可以讓再次找到對應(yīng)子路由,從而解決再次點擊主路由頁面空白的bug。

總結(jié)

以上所述是小編給大家介紹的vue 路由嵌套高亮問題的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對億速云網(wǎng)站的支持!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI