最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2020年08月06日 08:55:00   作者:Lena_葉  
這篇文章主要介紹了Vue頁面手動刷新,實現(xiàn)導(dǎo)航欄激活項還原到初始狀態(tài),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

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

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

<template>
 <el-menu :default-active="defaultActiveIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect" :router="true">
     <el-menu-item index="/">工作臺</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ù),
  // 此時 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; // 獲取路由對象
   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, // 只有一個節(jié)點
   iconCls: 'icon-home', // 圖標(biāo)樣式class
   menuShow: true,
   children: [
    { path: '/dashboard', component: Dashboard, name: '首頁', menuShow: true }
   ]
  },
  {
   path: '/mySet',
   component: HomeNav,
   name: '我的設(shè)置',
   iconCls: 'el-icon-menu',
   menuShow: true,
   children: [
    { path: '/mySet/plan', component: Plan, name: '行程計劃', 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, // 只有一個節(jié)點
   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, // 只有一個節(jié)點
   iconCls: 'el-icon-menu',
   menuShow: true,
   children: [
    { path: '/enterprise/add', component: EnterpriseAdd, name: '企業(yè)添加', menuShow: true }
   ]
  },
  {
   path: '/enterpriseValidate',
   component: EnterpriseNav,
   name: 'enterpriseValidate',
   leaf: true, // 只有一個節(jié)點
   iconCls: 'el-icon-menu',
   menuShow: true,
   children: [
    { path: '/enterprise/validate', component: EnterpriseValidate, name: '企業(yè)認證', menuShow: true }
   ]
  }
 ]
}
]

補充知識:vue手動刷新視圖以及其他小問題

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

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

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

2.在vue中使用setTimeout

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

以上這篇Vue頁面手動刷新,實現(xiàn)導(dǎo)航欄激活項還原到初始狀態(tài)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue.js結(jié)合SortableJS實現(xiàn)樹形數(shù)據(jù)拖拽

    Vue.js結(jié)合SortableJS實現(xiàn)樹形數(shù)據(jù)拖拽

    本文主要介紹了Vue.js結(jié)合SortableJS實現(xiàn)樹形數(shù)據(jù)拖拽,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • vue組件開發(fā)props驗證的實現(xiàn)

    vue組件開發(fā)props驗證的實現(xiàn)

    這篇文章主要介紹了vue組件開發(fā)props驗證的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02
  • 解決vue-loader加載不上的問題

    解決vue-loader加載不上的問題

    這篇文章主要介紹了解決vue-loader加載不上的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • 基于Vue的文字跑馬燈組件(npm 組件包)

    基于Vue的文字跑馬燈組件(npm 組件包)

    這篇文章主要介紹了基于Vue的文字跑馬燈組件(npm 組件包),需要的朋友可以參考下
    2017-05-05
  • Vue+Echarts實現(xiàn)繪制多設(shè)備狀態(tài)甘特圖

    Vue+Echarts實現(xiàn)繪制多設(shè)備狀態(tài)甘特圖

    這篇文章主要為大家詳細介紹了Vue如何結(jié)合Echarts實現(xiàn)繪制多設(shè)備狀態(tài)甘特圖,文中的示例代碼講解詳細,有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • 關(guān)于VUE點擊父組件按鈕跳轉(zhuǎn)到子組件的問題及解決方案

    關(guān)于VUE點擊父組件按鈕跳轉(zhuǎn)到子組件的問題及解決方案

    本文主要介紹了在Vue框架中,如何通過父組件的點擊事件打開子組件中的彈窗并展示表格內(nèi)容,主要步驟包括在父組件中定義數(shù)據(jù)屬性,創(chuàng)建并定義子組件的彈窗和表格內(nèi)容,通過props屬性和自定義事件實現(xiàn)父子組件間的數(shù)據(jù)傳遞和方法調(diào)用
    2024-10-10
  • webstorm添加*.vue文件支持

    webstorm添加*.vue文件支持

    這篇文章主要介紹了webstorm添加*.vue文件支持,webstorm很多的插件內(nèi)置,不用安裝插件,下面嘗試用vue和es6做項目,有興趣的可以了解一下
    2018-05-05
  • vue中?render?函數(shù)功能與原理分析

    vue中?render?函數(shù)功能與原理分析

    這篇文章主要介紹了vue中?render?函數(shù)功能與原理,結(jié)合實例形式分析了vue中render函數(shù)的基本功能、原理及相關(guān)操作注意事項,需要的朋友可以參考下
    2023-06-06
  • VUE跨域詳解以及常用解決跨域的方法

    VUE跨域詳解以及常用解決跨域的方法

    跨域指瀏覽器不允許當(dāng)前頁面的所在的源去請求另一個源的數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于VUE跨域詳解以及常用解決跨域的方法,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-07-07
  • vue.js學(xué)習(xí)筆記:如何加載本地json文件

    vue.js學(xué)習(xí)筆記:如何加載本地json文件

    這篇文章主要介紹了vue.js學(xué)習(xí)筆記:如何加載本地json文件,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧。
    2017-01-01

最新評論

济宁市| 临邑县| 汶川县| 西青区| 曲靖市| 洪江市| 天镇县| 沭阳县| 上饶市| 唐海县| 蓬安县| 衡南县| 景德镇市| 沂水县| 舟山市| 开阳县| 仪征市| 锡林郭勒盟| 蒙阴县| 梧州市| 甘南县| 福鼎市| 泾阳县| 双鸭山市| 来宾市| 疏勒县| 永新县| 华宁县| 通海县| 东乡族自治县| 五台县| 高州市| 报价| 随州市| 永仁县| 明水县| 二手房| 吉木萨尔县| 永靖县| 平利县| 临高县|