vue 路由嵌套高亮問題的解決方法
正常路由嵌套是沒有問題的,但是如果你已經(jīng)在當(dāng)前主路由頁面了,然后再次點(diǎn)擊主路由就會(huì)出現(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)計(jì)</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)計(jì)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)計(jì)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)計(jì)3</a></router-link> </ul> <!--navtabbar end--> <!--內(nèi)容 begin--> <router-view></router-view> </div>
子路由JS:
exprot default{ mounted() { this.routerHop(); }, updated() { //當(dāng)前頁再次點(diǎn)擊主路由時(shí)重新判斷跳轉(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(){ // 客戶賬號(hào)登錄只顯示錯(cuò)誤統(tǒng)計(jì)分析頁面 if(this.isPerson() === false){ return router.push({name: 'statistics1', params: {showPanel: false}}); } router.push({name: 'statistics3', params: {showPanel: false}}); }, } } }
因?yàn)橐呀?jīng)在當(dāng)前子路由頁面,當(dāng)再次點(diǎn)擊主路由導(dǎo)航時(shí),無法觸發(fā)mounted鉤子。通過updated這個(gè)鉤子函數(shù)可以讓再次找到對應(yīng)子路由,從而解決再次點(diǎn)擊主路由頁面空白的bug。
總結(jié)
以上所述是小編給大家介紹的vue 路由嵌套高亮問題的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
vue 1.x 交互實(shí)現(xiàn)仿百度下拉列表示例
本篇文章主要介紹了vue 1.x 交互實(shí)現(xiàn)仿百度下拉列表示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10Vue項(xiàng)目查看當(dāng)前使用的elementUI版本的方法
今天小編就為大家分享一篇Vue項(xiàng)目查看當(dāng)前使用的elementUI版本的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09vue-cli3.0實(shí)現(xiàn)一個(gè)多頁面應(yīng)用的歷奇經(jīng)歷記錄總結(jié)
這篇文章主要介紹了vue-cli3.0實(shí)現(xiàn)一個(gè)多頁面應(yīng)用的歷奇經(jīng)歷,總結(jié)分析了vue-cli3.0實(shí)現(xiàn)一個(gè)多頁面應(yīng)用遇到的問題與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-03-03vue如何動(dòng)態(tài)實(shí)時(shí)的顯示時(shí)間淺析
這篇文章主要給大家介紹了關(guān)于vue如何動(dòng)態(tài)實(shí)時(shí)的顯示時(shí)間,以及vue時(shí)間戳 獲取本地時(shí)間實(shí)時(shí)更新的相關(guān)資料,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05解讀element-ui使用el-upload,before-upload函數(shù)不好使的問題
這篇文章主要介紹了解讀element-ui使用el-upload,before-upload函數(shù)不好使的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03解決vue axios的封裝 請求狀態(tài)的錯(cuò)誤提示問題
今天小編就為大家分享一篇解決vue axios的封裝 請求狀態(tài)的錯(cuò)誤提示問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09Vue ElementUI中el-table表格嵌套樣式問題小結(jié)
這篇文章主要介紹了Vue ElementUI中el-table表格嵌套樣式問題小結(jié),兩個(gè)表格嵌套,當(dāng)父表格有children數(shù)組時(shí)子表格才展示,對Vue ElementUI中el-table表格嵌套樣式問題感興趣的朋友跟隨小編一起看看吧2024-02-02