這次帶給大家怎樣實現vue路由嵌套高亮,實現vue路由嵌套高亮的注意事項有哪些,下面就是實戰案例,一起來看一下。
看程式碼:
//主路由通过v-for循环出来 <p 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">数据统计</a> <router-link v-for="page in getPages" class="list-group-item" :to="page.pageUrl">{{page.pageName}}</router-link> </p> //次路由通过URL拼接的方式导航到子路由页面 <p 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" >统计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" >统计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" >统计3</a></router-link> </ul> <!--navtabbar end--> <!--内容 begin--> <router-view></router-view> </p>
子路由JS:
exprot default{ mounted() { this.routerHop(); }, updated() { //当前页再次点击主路由时重新判断跳转 var url = this.$route.path; if (url === "/statistics/dataStatistics") { this.routerHop(); } }, methods: { //权限判断 isPerson() { let user = this.$store.state.user.userInfo; if (user.userType == 1) { return true } return false; }, routerHop(){ // 客户账号登录只显示错误统计分析页面 if(this.isPerson() === false){ return router.push({name: 'statistics1', params: {showPanel: false}}); } router.push({name: 'statistics3', params: {showPanel: false}}); }, } } }
因為已經在目前子路由頁面,當再次點擊主路由導航時,無法觸發mounted鉤子。透過updated這個鉤子函數可以讓再次找到對應子路由,從而解決再次點選主路由頁面空白的bug。
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
以上是怎麼實現vue路由嵌套高亮的詳細內容。更多資訊請關注PHP中文網其他相關文章!