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

vue 使用localstorage實(shí)現(xiàn)面包屑的操作

 更新時(shí)間:2020年11月16日 09:58:53   作者:Cassie、  
這篇文章主要介紹了vue 使用localstorage實(shí)現(xiàn)面包屑的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

mutation.js代碼:

changeRoute(state, val) {
    let routeList = state.routeList;
    let isFind = false;
    let findeIdex = 0;

    //菜單欄和下拉的二級(jí)菜單
    if (val['type'] == 'header' || val['type'] == 'secondHeader')   {
      routeList.length = 0;
      //頂級(jí)菜單清除緩存
      localStorage.removeItem("routeList");
    }
    let routes = routeList;
    let localStorageList = localStorage.getItem('routeList');
    if (localStorageList) {
      //當(dāng)前頁(yè)刷新,使用緩存數(shù)據(jù)
      routes = JSON.parse(localStorageList as any);
    }
    //遍歷是否有存入當(dāng)前路由位置
    for (let i = 0; i < routes.length; i++) {
      isFind = routes[i]['name'] == val['name'];
      if (isFind) {
        findeIdex = i;
        break;
      }
    };
    if (isFind) {
      //有的話,清除當(dāng)前路由以后的數(shù)據(jù)
      routes.splice(findeIdex + 1, routes.length - findeIdex - 1);
      //修改緩存
      localStorage.setItem('routeList', JSON.stringify(routes));
    } else {
      //存入全局變量
      routes.push(val);
      //設(shè)置緩存
      localStorage.setItem('routeList', JSON.stringify(routes));
    }
  }

頁(yè)面使用:

//獲取面包屑緩存
  let localStorageList1 = localStorage.getItem('routeList');
  //ts寫(xiě)法 as any
  this.routeList = JSON.parse(localStorageList1 as any) 
   ? JSON.parse(localStorageList1 as any)
   : { name: 'test', url: '/test' };

知識(shí)點(diǎn):

1、localstorage

2、JSON.stringify()的作用是將 JavaScript 值轉(zhuǎn)換為 JSON 字符串,JSON.parse()將JSON字符串轉(zhuǎn)為一個(gè)對(duì)象

補(bǔ)充知識(shí):vue+elementUI動(dòng)態(tài)生成面包屑導(dǎo)航

項(xiàng)目需要?jiǎng)討B(tài)生成面包屑導(dǎo)航,并且首頁(yè)可以點(diǎn)擊.其余為路徑顯示

<el-menu :unique-opened="true" router :default-active="$route.path" @select="handleSelect">
    <div class="user-menu-box" v-for="menu in menus" :key="menu.id">
      <el-menu-item v-if="!menu.child" :index="menu.path">
        <icon :name="menu.icon" :w="20" :h="20"></icon>
        <span slot="title" v-text="menu.name"></span>
      </el-menu-item>
      <el-submenu v-if="menu.child" :index="menu.path">
        <template slot="title">
          <icon :name="menu.icon" :w="20" :h="20"></icon>
          <span slot="title" v-text="menu.name"></span>
        </template>
        <el-menu-item-group>
          <el-menu-item v-for="subMenu in menu.child" :key="subMenu.id" v-text="subMenu.name"
            :index="subMenu.path"></el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </div>
</el-menu>

上面的代碼是elementUI組件的樣式,根據(jù)項(xiàng)目需要做了修改,搬運(yùn)的時(shí)候根據(jù)項(xiàng)目自己改改

export default {
  data () {
    return {
      activeMenu: '',
      indexBreadcrumbs: [],
      menus: [{
        id: '1',
        name: '門(mén)戶管理',
        icon: 'menhuguanli',
        path: '#2',
        child: [{
          id: '1-1',
          name: '輪播圖',
          path: '/backstage/protaManage/turns'
        }, {
          id: '1-2',
          name: '基礎(chǔ)數(shù)據(jù)',
          path: '/backstage/protaManage/basis'
        }, {
          id: '1-3',
          name: '分類管理',
          path: '/backstage/protaManage/classify'
        }, {
          id: '1-4',
          name: '內(nèi)容發(fā)布',
          path: '/backstage/protaManage/content'
        }]
      }, {
        id: '2',
        name: '我的云盤(pán)',
        icon: 'yunpan',
        path: '/backstage/yunManage'
      }, {
        id: '3',
        name: '管理菜單',
        icon: 'shezhi',
        path: '/backstage/menusManage'
      }, {
        id: '4',
        name: '編輯板塊',
        icon: 'fabuzhongxin',
        path: '/backstage/editPlate'
      }]
    }
  },
  watch: {
    $route () {
      this.handChange()
    }
  },
  computed: {
    breadcrumbList () {
      let breadcrumbs = []
      let menuList = this.menus
      this.indexBreadcrumbs.map(item => {
        for (let i = 0; i < menuList.length; i++) {
          if (item === menuList[i].path) {
            breadcrumbs.push(menuList[i])
            if (menuList[i].child) {
              menuList = menuList[i].child
            }
            break;
          }
        }
      })
      return breadcrumbs
    }
  },
  methods: {
    handChange () {
      this.$emit('hand-change', this.breadcrumbList)
    },
    handleSelect (index, indexPath) {
      this.indexBreadcrumbs = indexPath
    }
  },
  created () {
    this.handChange()
  }
}

上面的代碼是模擬的數(shù)據(jù),調(diào)用elememtUI的組件導(dǎo)航菜單的中的@select方法,有兩個(gè)參數(shù),可以自行打印

然后在computed中計(jì)算當(dāng)前選中的是哪一部分,取到返回值,然后$emit傳給父組件,

<el-breadcrumb separator-class="el-icon-arrow-right">
   <el-breadcrumb-item :to="{ path: '/backstage' }">首頁(yè)</el-breadcrumb-item>
   <el-breadcrumb-item v-for="o in breadcrumbList" :key="o.id">{{o.name}}
   </el-breadcrumb-item>
 </el-breadcrumb>

父組件中取到子組件傳過(guò)來(lái)的值后,直接渲染就行了

以上這篇vue 使用localstorage實(shí)現(xiàn)面包屑的操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 解決Ant Design Modal內(nèi)嵌Form表單initialValue值不動(dòng)態(tài)更新問(wèn)題

    解決Ant Design Modal內(nèi)嵌Form表單initialValue值不動(dòng)態(tài)更新問(wèn)題

    這篇文章主要介紹了解決Ant Design Modal內(nèi)嵌Form表單initialValue值不動(dòng)態(tài)更新問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-10-10
  • 使用Vue2實(shí)現(xiàn)簡(jiǎn)單的購(gòu)物車功能(可直接使用)

    使用Vue2實(shí)現(xiàn)簡(jiǎn)單的購(gòu)物車功能(可直接使用)

    這篇文章主要給大家介紹了如何使用Vue2實(shí)現(xiàn)簡(jiǎn)單的購(gòu)物車功能,文中有相關(guān)的代碼示例,對(duì)我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2023-08-08
  • vuex(vue狀態(tài)管理)的特殊應(yīng)用案例分享

    vuex(vue狀態(tài)管理)的特殊應(yīng)用案例分享

    Vuex 是一個(gè)專為 Vue.js 應(yīng)用程序開(kāi)發(fā)的狀態(tài)管理模式。它采用集中式存儲(chǔ)管理應(yīng)用的所有組件的狀態(tài),并以相應(yīng)的規(guī)則保證狀態(tài)以一種可預(yù)測(cè)的方式發(fā)生變化。
    2020-03-03
  • Vue3+Canvas實(shí)現(xiàn)簡(jiǎn)易的貪吃蛇游戲

    Vue3+Canvas實(shí)現(xiàn)簡(jiǎn)易的貪吃蛇游戲

    貪吃蛇作為一個(gè)經(jīng)典的小游戲,是很多人兒時(shí)的記憶,當(dāng)時(shí)的掌機(jī)、諾基亞手機(jī)里面都有它的身影。本文將用Vue3?Canvas來(lái)復(fù)刻一下這款游戲,感興趣的可以了解一下
    2022-07-07
  • 前端使用vue實(shí)現(xiàn)token無(wú)感刷新的三種方案解析

    前端使用vue實(shí)現(xiàn)token無(wú)感刷新的三種方案解析

    這篇文章主要為大家介紹了前端使用vue實(shí)現(xiàn)token無(wú)感刷新的三種方案詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • 簡(jiǎn)單了解Vue + ElementUI后臺(tái)管理模板

    簡(jiǎn)單了解Vue + ElementUI后臺(tái)管理模板

    這篇文章主要介紹了簡(jiǎn)單了解Vue + ElementUI后臺(tái)管理模板,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • vue3保存屬性自動(dòng)換行問(wèn)題及解決

    vue3保存屬性自動(dòng)換行問(wèn)題及解決

    這篇文章主要介紹了vue3保存屬性自動(dòng)換行問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue指令v-html和v-text

    vue指令v-html和v-text

    這篇文章主要介紹了 vue指令v-html和v-text,文章圍繞vue指令v-html和v-text的相關(guān)資料展開(kāi)詳細(xì)內(nèi)容,需要的小伙伴可以參考一下,希望對(duì)大家有所幫助
    2021-11-11
  • vue-form表單驗(yàn)證是否為空值的實(shí)例詳解

    vue-form表單驗(yàn)證是否為空值的實(shí)例詳解

    今天小編就為大家分享一篇vue-form表單驗(yàn)證是否為空值的實(shí)例詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • vue中$emit的用法詳解

    vue中$emit的用法詳解

    這篇文章主要介紹了vue中$emit的用法詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08

最新評(píng)論

库伦旗| 利津县| 新绛县| 濉溪县| 石河子市| 德格县| 海盐县| 高陵县| 寿宁县| 苍南县| 阳西县| 栾川县| 东乌珠穆沁旗| 奎屯市| 犍为县| 潼南县| 石柱| 福建省| 出国| 桃源县| 富平县| 华安县| 莒南县| 琼海市| 连州市| 宁津县| 上蔡县| 柳江县| 巴南区| 宣威市| 嘉禾县| 长汀县| 乾安县| 潮州市| 虞城县| 涡阳县| 利川市| 淮滨县| 新河县| 阜平县| 郴州市|