国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Vue頁(yè)面手動(dòng)刷新,實(shí)現(xiàn)導(dǎo)航欄激活項(xiàng)還原到初始狀態(tài)

瀏覽:77日期:2022-12-15 11:55:45

場(chǎng)景描述:在頁(yè)面中存在頂部導(dǎo)航和左側(cè)導(dǎo)航,左側(cè)導(dǎo)航和右側(cè)內(nèi)容區(qū)使用了命名視圖實(shí)現(xiàn),點(diǎn)擊左側(cè)導(dǎo)航的鏈接時(shí),右側(cè)內(nèi)容區(qū)相應(yīng)顯示不同組件內(nèi)容。問題:在當(dāng)前鏈接手動(dòng)刷新瀏覽器(例如:瀏覽器地址為/enterprise/list),頂部導(dǎo)航激活項(xiàng)還原到初始狀態(tài)(這里默認(rèn)是“工作臺(tái)”項(xiàng))。

原理:每次刷新都會(huì)重新實(shí)例化Vue,也就是會(huì)調(diào)用created方法。

<template> <el-menu :default-active='defaultActiveIndex' mode='horizontal' @select='handleSelect' :router='true'>   <el-menu-item index='/'>工作臺(tái)</el-menu-item><el-menu-item index='/enterpriseManager'>企業(yè)管理</el-menu-item><el-menu-item index='/orderManager'>訂單管理</el-menu-item><el-menu-item index='/systemManager'>系統(tǒng)管理</el-menu-item></el-menu></template><script>export default { name: ’app’, data () { return { defaultActiveIndex: '/' } }, created() { // 組件創(chuàng)建完后獲取數(shù)據(jù), // 此時(shí) data 已經(jīng)被 observed 了 this.fetchData() }, methods: { handleSelect(index){ this.defaultActiveIndex = index; }, jumpTo(url){ this.defaultActiveIndex = url; this.$router.push(url); //用go刷新 }, fetchData () { var cur_path = this.$route.path; //獲取當(dāng)前路由 var routers = this.$router.options.routes; // 獲取路由對(duì)象 var nav_type = ''; for(var i=0; i<routers.length; i++){ var children = routers[i].children; if(children){ for(var j=0; j<children.length; j++){ var grand_children = children[j].children; if(grand_children){ for(var k=0; k<grand_children.length; k++){if(grand_children[k].path == cur_path){ nav_type = routers[i].type; break;} } } } } } if(nav_type == 'home'){ this.defaultActiveIndex = '/'; } else if(nav_type == 'enterprise'){ this.defaultActiveIndex = '/enterpriseManager'; } } } watch: { ’$route’: ’fetchData’ }}</script>

附上router配置格式:

export default [{ path: ’/’, type: ’home’, //自定義type區(qū)分不同模塊菜單 name: ’home’, redirect: ’/dashboard’, component: Home, menuShow: true, children: [ { path: ’/dashboard’, component: HomeNav, name: ’dashboard’, leaf: true, // 只有一個(gè)節(jié)點(diǎn) iconCls: ’icon-home’, // 圖標(biāo)樣式class menuShow: true, children: [ { path: ’/dashboard’, component: Dashboard, name: ’首頁(yè)’, menuShow: true } ] }, { path: ’/mySet’, component: HomeNav, name: ’我的設(shè)置’, iconCls: ’el-icon-menu’, menuShow: true, children: [ { path: ’/mySet/plan’, component: Plan, name: ’行程計(jì)劃’, menuShow: true }, { path: ’/mySet/maillist’, component: Maillist, name: ’通訊錄’, menuShow: true } ] } ]},{ path: ’/enterpriseManager’, type: ’enterprise’, name: ’enterprise’, component: Home, redirect: ’/enterprise/list’, menuShow: true, children: [ { path: ’/enterpriseList’, component: EnterpriseNav, name: ’enterpriseList’, leaf: true, // 只有一個(gè)節(jié)點(diǎn) iconCls: ’icon-home’, // 圖標(biāo)樣式class menuShow: true, children: [ { path: ’/enterprise/list’, component: EnterpriseList, name: ’企業(yè)列表’, menuShow: true } ] }, { path: ’/enterpriseAdd’, component: EnterpriseNav, name: ’enterpriseAdd’, leaf: true, // 只有一個(gè)節(jié)點(diǎn) iconCls: ’el-icon-menu’, menuShow: true, children: [ { path: ’/enterprise/add’, component: EnterpriseAdd, name: ’企業(yè)添加’, menuShow: true } ] }, { path: ’/enterpriseValidate’, component: EnterpriseNav, name: ’enterpriseValidate’, leaf: true, // 只有一個(gè)節(jié)點(diǎn) iconCls: ’el-icon-menu’, menuShow: true, children: [ { path: ’/enterprise/validate’, component: EnterpriseValidate, name: ’企業(yè)認(rèn)證’, menuShow: true } ] } ]}]

補(bǔ)充知識(shí):vue手動(dòng)刷新視圖以及其他小問題

最近把手頭上一個(gè)使用angularJS+jquery各種七七八八組件寫的頁(yè)面拿vue+elementUI重寫了一邊, 真是極度絲滑, 記錄一些vue和elementUI的小問題

1.如果vue中的數(shù)據(jù)結(jié)構(gòu)比較龐大的話, 十分有可能會(huì)出現(xiàn)model更新而視圖不更新/model和視圖都不更新也不報(bào)錯(cuò)的情況, 此時(shí)需要手動(dòng)刷新vue的數(shù)據(jù), 在change或click事件中, 使用this.$forceUpdate()手動(dòng)刷新視圖

//像這樣 changeSef: function () { //手動(dòng)刷新視圖 var that = this; that.$forceUpdate(); },

2.在vue中使用setTimeout

//錯(cuò)誤示范setTimeout(bidOrderInit, 200);//上面那樣是不行的,網(wǎng)上查了下, 大致是說(shuō)在setTimeout中this指向window對(duì)象, //于是乎被定時(shí)的方法中就使用不到vue的this對(duì)象了//正確示范//可以無(wú)視對(duì)ie的支持時(shí)setTimeout(()=> { this.bidOrderInit();}, 200);//需要兼容ie時(shí)setTimeout(function () { this.bidOrderInit();}, 200);

以上這篇Vue頁(yè)面手動(dòng)刷新,實(shí)現(xiàn)導(dǎo)航欄激活項(xiàng)還原到初始狀態(tài)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Vue
主站蜘蛛池模板: 日韩 国产 欧美视频一区二区三区 | 自拍视频区 | 韩日一区二区 | 国产乱理片在线观看夜 | 经典国产乱子伦精品视频 | 国产一区二区播放 | 久久国产欧美日韩精品 | 国产精品亚洲二区 | 欧美一级做一级爱a做片性 欧美一欧美一级毛片 | 99久久免费中文字幕精品 | 精品国产欧美一区二区五十路 | a级毛片在线播放 | 国产特黄特色一级特色大片 | 免费一级片网站 | 国产精品国产高清国产专区 | 午夜在线亚洲 | 美女视频永久黄网站在线观看 | 玖玖在线免费视频 | 成人亚洲精品 | 九九视频在线观看视频23 | 97在线视频免费公开观看 | 久久精品九九 | 一级做a爱过程免费观看 | 99久久精品国产一区二区小说 | 一级伦理电线在2019 | 欧美成人午夜做爰视频在线观看 | 国产午夜亚洲精品一区网站 | 精品久久久久久久久中文字幕 | 日韩精品中文字幕在线 | 久久综合伊人77777 | 免费国产a理论片 | 午夜91理论片 | 日本视频播放免费线上观看 | 亚洲欧美日韩中文字幕在线 | 亚洲国产一区二区a毛片日本 | 欧美日韩乱国产 | 亚洲精品欧美日韩 | 国产精品a人片在线观看 | 成人免费视频日本 | 免费国产一级特黄久久 | 久草福利社 |