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

vue+elementUI如何實(shí)現(xiàn)頂部路由標(biāo)簽跳轉(zhuǎn)

 更新時(shí)間:2024年03月19日 09:43:01   作者:寫(xiě)B(tài)ug的大雄  
這篇文章主要介紹了vue+elementUI如何實(shí)現(xiàn)頂部路由標(biāo)簽跳轉(zhuǎn)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

引言

后臺(tái)管理系統(tǒng)中,為了方便使用者跳轉(zhuǎn)已經(jīng)訪問(wèn)過(guò)的頁(yè)面,需要實(shí)現(xiàn)頂部路由標(biāo)簽跳轉(zhuǎn)到訪問(wèn)過(guò)頁(yè)面的功能,因此封裝成組件方便使用

封裝組件

<!-- TagsView/levelScroll.vue -->    
<template>
  <el-scrollbar
    ref="scrollContainer"
    :vertical="false"
    class="scroll-container"
    @wheel.native.prevent="handleScroll"
  >
    <slot />
  </el-scrollbar>
</template>
<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
  data () {
    return {
      left: 0
    };
  },
  computed: {
    scrollWrapper () {
      return (this.$refs as any).scrollContainer.$refs.wrap;
    }
  },
  methods: {
    // 鼠標(biāo)滑動(dòng)事件
    handleScroll (e: { wheelDelta: number; deltaY: number }) {
      const eventDelta = e.wheelDelta || -e.deltaY * 40;
      const $scrollWrapper = this.scrollWrapper;
      $scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4;
    }
  }
});
</script>
<style lang="less" scoped>
.scroll-container {
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  width: 100%;
  /deep/.el-scrollbar__bar {
    bottom: 0px;
  }
  /deep/.el-scrollbar__wrap {
    height: 49px;
    // margin-bottom: -17px !important;
    // margin-right: -17px !important;
  }
}
</style>

vuex 文件

// modules/tagsView.ts
const state = {
  // 訪問(wèn)過(guò)的頁(yè)面標(biāo)簽
  visitedViews: [
    {
      path: '/dashboard/index',
      meta: { title: '首頁(yè)', affix: true }
    }
  ],
  // 訪問(wèn)過(guò)的頁(yè)面的 name 值
  cachedViews: []
};

const mutations = {
  // 添加訪問(wèn)過(guò)的路由
  ADD_VISITED_VIEW: (state: { visitedViews: any[] }, view: any) => {
    if (state.visitedViews.some((v) => v.path === view.path)) return;
    state.visitedViews.push(
      Object.assign({}, view, {
        title: view.meta.title
      })
    );
  },
  // 添加訪問(wèn)過(guò)的路由 name
  ADD_CACHED_VIEW: (state: { cachedViews: any[] }, view: { name: string }) => {
    if (state.cachedViews.includes(view.name)) return;
    state.cachedViews.push(view.name);
  },

  // 刪除當(dāng)前路由
  DEL_VISITED_VIEW: (
    state: { visitedViews: any[] },
    view: { path: string }
  ) => {
    for (const [i, v] of state.visitedViews.entries()) {
      if (v.path === view.path) {
        state.visitedViews.splice(i, 1);
        break;
      }
    }
  },
  // 刪除當(dāng)前路由 name
  DEL_CACHED_VIEW: (state: { cachedViews: any[] }, view: { name: string }) => {
    const index = state.cachedViews.indexOf(view.name);
    index > -1 && state.cachedViews.splice(index, 1);
  },

  // 刪除當(dāng)前路由之外的路由
  DEL_OTHERS_VISITED_VIEWS: (
    state: { visitedViews: any[] },
    view: { path: string }
  ) => {
    state.visitedViews = state.visitedViews.filter((v) => {
      return v.meta.affix || v.path === view.path;
    });
  },
  // 刪除當(dāng)前路由之外的路由 name
  DEL_OTHERS_CACHED_VIEWS: (
    state: { cachedViews: any[] },
    view: { name: string }
  ) => {
    const index = state.cachedViews.indexOf(view.name);
    if (index > -1) {
      state.cachedViews = state.cachedViews.slice(index, index + 1);
    } else {
      state.cachedViews = [];
    }
  },

  // 刪除全部訪問(wèn)過(guò)的路由
  DEL_ALL_VISITED_VIEWS: (state: { visitedViews: any[] }) => {
    const affixTags = state.visitedViews.filter((tag) => tag.meta.affix);
    state.visitedViews = affixTags;
  },
  // 刪除全部訪問(wèn)過(guò)的路由 name
  DEL_ALL_CACHED_VIEWS: (state: { cachedViews: any[] }) => {
    state.cachedViews = [];
  }
};

const actions = {
  // 添加訪問(wèn)過(guò)的路由
  addVisitedView ({ commit }: { commit: any }, view: any) {
    commit('ADD_VISITED_VIEW', view);
  },
  // 添加訪問(wèn)過(guò)的路由 name
  addCachedView ({ commit }: { commit: any }, view: any) {
    commit('ADD_CACHED_VIEW', view);
  },
  addView ({ dispatch }: { dispatch: any }, view: any) {
    dispatch('addVisitedView', view);
    dispatch('addCachedView', view);
  },

  // 刪除當(dāng)前路由
  delVisitedView ({ commit }: { commit: any }, view: any) {
    commit('DEL_VISITED_VIEW', view);
  },
  // 刪除當(dāng)前路由 name
  delCachedView ({ commit }: { commit: any }, view: any) {
    commit('DEL_CACHED_VIEW', view);
  },
  delView ({ dispatch }: { dispatch: any }, view: any) {
    dispatch('delVisitedView', view);
    dispatch('delCachedView', view);
  },

  // 刪除當(dāng)前路由之外的路由
  delOthersVisitedViews ({ commit }: { commit: any }, view: any) {
    commit('DEL_OTHERS_VISITED_VIEWS', view);
  },
  // 刪除當(dāng)前路由之外的路由 namw
  delOthersCachedViews ({ commit }: { commit: any }, view: any) {
    commit('DEL_OTHERS_CACHED_VIEWS', view);
  },
  delOthersViews ({ dispatch }: { dispatch: any }, view: any) {
    dispatch('delOthersVisitedViews', view);
    dispatch('delOthersCachedViews', view);
  },

  // 刪除全部訪問(wèn)過(guò)的路由
  delAllVisitedViews ({ commit }: { commit: any }) {
    commit('DEL_ALL_VISITED_VIEWS');
  },
  // 刪除全部訪問(wèn)過(guò)的路由 name
  delAllCachedViews ({ commit }: { commit: any }) {
    commit('DEL_ALL_CACHED_VIEWS');
  },
  delAllViews ({ dispatch }: { dispatch: any }, view: any) {
    dispatch('delAllVisitedViews', view);
    dispatch('delAllCachedViews', view);
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};

// getters.ts
const getters = {
  // 訪問(wèn)的頁(yè)面標(biāo)簽
  visitedViews: (state: any) => state.tagsView.visitedViews,
  // 訪問(wèn)的頁(yè)面標(biāo)簽 name
  cachedViews: (state: any) => state.tagsView.cachedViews
};
export default getters;

router 文件

import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '@/views/login/index.vue';
import Layout from '@/layout/index.vue';

Vue.use(VueRouter);

/**
 * hidden 表示是否需要在側(cè)邊導(dǎo)航欄出現(xiàn) ,true表示不需要
 * isFirst 表示是否只有一級(jí)權(quán)限,只出現(xiàn)在只有一個(gè)子集,沒(méi)有其他孫子集
 * 當(dāng)權(quán)限擁有多個(gè)子集或者孫子集,一級(jí)權(quán)限需要加上 meta
 * 二級(jí)權(quán)限擁有子集,也必須有 meta
 */

// 基礎(chǔ)路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/',
    redirect: '/dashboard',
    hidden: true
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    hidden: true
  },
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/index',
    isFirst: true,
    children: [
      {
        path: 'index',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: {
          title: '首頁(yè)',
          icon: 'el-icon-location'
        }
      }
    ]
  }
];

// 動(dòng)態(tài)路由
export const asyncRoutes = [
  {
    path: '/form',
    component: Layout,
    redirect: '/form/index',
    isFirst: true,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index.vue'),
        meta: {
          title: '表單',
          role: 'form',
          icon: 'el-icon-location'
        }
      }
    ]
  },
  {
    path: '/editor',
    component: Layout,
    redirect: '/editor/index',
    meta: {
      role: 'editors',
      title: '總富文本',
      icon: 'el-icon-location'
    },
    children: [
      {
        path: 'index',
        name: 'Editor',
        component: () => import('@/views/editor/index.vue'),
        meta: {
          title: '富文本',
          role: 'editor',
          icon: 'el-icon-location'
        }
      },
      {
        path: 'two',
        name: 'Two',
        redirect: '/editor/two/three',
        component: () => import('@/views/editor/two.vue'),
        meta: {
          title: '二級(jí)導(dǎo)航',
          role: 'two',
          icon: 'el-icon-location'
        },
        children: [
          {
            path: 'three',
            name: 'Three',
            component: () => import('@/views/editor/three.vue'),
            meta: {
              title: '三級(jí)導(dǎo)航',
              role: 'three',
              icon: 'el-icon-location'
            }
          },
          {
            path: 'four',
            name: 'Four',
            component: () => import('@/views/editor/four.vue'),
            meta: {
              title: '三級(jí)導(dǎo)航2',
              role: 'four',
              icon: 'el-icon-location'
            }
          }
        ]
      }
    ]
  },
  {
    path: '/tree',
    component: Layout,
    redirect: '/tree/index',
    isFirst: true,
    children: [
      {
        path: 'index',
        name: 'Tree',
        component: () => import('@/views/tree/index.vue'),
        meta: {
          title: '樹(shù)狀圖',
          role: 'tree',
          icon: 'el-icon-location'
        }
      }
    ]
  },
  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/index',
    isFirst: true,
    children: [
      {
        path: 'index',
        name: 'Excel',
        component: () => import('@/views/excel/index.vue'),
        meta: {
          title: '導(dǎo)入導(dǎo)出',
          role: 'excel',
          icon: 'el-icon-location'
        }
      }
    ]
  }
];

// 出錯(cuò)跳轉(zhuǎn)的路由
export const error = [
  // 404
  {
    path: '/404',
    component: () => import('@/views/error/index.vue'),
    hidden: true
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
];

const createRouter = () =>
  new VueRouter({
    scrollBehavior: () => ({
      x: 0,
      y: 0
    }),
    routes: constantRoutes
  });

const router = createRouter();

// 刷新路由
export function resetRouter () {
  const newRouter = createRouter();
  (router as any).matcher = (newRouter as any).matcher;
}

export default router;

頁(yè)面中使用

<!-- 一般在主體布局頁(yè)面使用 -->
<template>
  <div class="layout">
     ......
    <el-container :class="{ hideSidebar: isCollapse }">
      ......
      <!-- 主體內(nèi)容 -->
      <el-main>
        <!-- 訪問(wèn)過(guò)的路由標(biāo)簽 -->
        <tags-view></tags-view>
        <keep-alive :include="cachedViews">
          <router-view :key="$route.path" />
        </keep-alive>
      </el-main>
    </el-container>
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import { mapGetters } from 'vuex';
import SubMenu from '@/components/SubMenu/index.vue';
import MyBreadcrumb from '@/components/Breadcrumb/index.vue';
import TagsView from '@/components/TagsView/index.vue';
import { resetRouter } from '@/router';

export default Vue.extend({
  computed: {
    // 路由
    ...mapGetters(['cachedViews'])
  },
  components: {
    TagsView
  }
});
</script>

總結(jié)

參考網(wǎng)上資料進(jìn)行封裝修改,具體需求可根據(jù)項(xiàng)目修改

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得

    詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得

    這篇文章主要介紹了詳解VUE-地區(qū)選擇器(V-Distpicker)組件使用心得,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • 基于vue3實(shí)現(xiàn)一個(gè)抽獎(jiǎng)小項(xiàng)目

    基于vue3實(shí)現(xiàn)一個(gè)抽獎(jiǎng)小項(xiàng)目

    在公司年會(huì)期間我做了個(gè)抽獎(jiǎng)小項(xiàng)目,非常棒,今天把他分享到腳本之家平臺(tái),供大家學(xué)習(xí)參考,對(duì)vue3實(shí)現(xiàn)抽獎(jiǎng)小項(xiàng)目感興趣的朋友一起看看吧
    2023-01-01
  • vue3?自定義指令控制按鈕權(quán)限的操作代碼

    vue3?自定義指令控制按鈕權(quán)限的操作代碼

    這篇文章主要介紹了vue3?自定義指令控制按鈕權(quán)限,為了提高用戶(hù)體驗(yàn),當(dāng)該按鈕無(wú)權(quán)使用時(shí),使用el-tooltip功能進(jìn)行提醒,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • 詳解基于vue的移動(dòng)web app頁(yè)面緩存解決方案

    詳解基于vue的移動(dòng)web app頁(yè)面緩存解決方案

    這篇文章主要介紹了詳解基于vue的移動(dòng)web app頁(yè)面緩存解決方案,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-08-08
  • Vue自定義指令使用方法詳解

    Vue自定義指令使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Vue自定義指令的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • vueScroll實(shí)現(xiàn)移動(dòng)端下拉刷新、上拉加載

    vueScroll實(shí)現(xiàn)移動(dòng)端下拉刷新、上拉加載

    這篇文章主要介紹了vueScroll實(shí)現(xiàn)移動(dòng)端下拉刷新、上拉加載,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • vue3實(shí)現(xiàn)密碼輸入框效果的示例代碼

    vue3實(shí)現(xiàn)密碼輸入框效果的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何利用vue3實(shí)現(xiàn)6位的密碼輸入框效果,文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-08-08
  • Vue獲取表單數(shù)據(jù)的方法

    Vue獲取表單數(shù)據(jù)的方法

    這篇文章主要為大家介紹了Vue獲取表單數(shù)據(jù)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-12-12
  • Vue2遷移Rsbuild詳細(xì)步驟

    Vue2遷移Rsbuild詳細(xì)步驟

    Rsbuild,一個(gè)基于Rspack的高效Web構(gòu)建工具,將Rspack的強(qiáng)大功能與易用性相結(jié)合,是你項(xiàng)目搭建的不二之選,Rsbuild不僅提供了開(kāi)箱即用的體驗(yàn),還引入了高性能的構(gòu)建機(jī)制,本文給大家介紹了Vue2遷移Rsbuild詳細(xì)步驟,需要的朋友可以參考下
    2024-10-10
  • Vue實(shí)現(xiàn)文件切片上傳功能的示例代碼

    Vue實(shí)現(xiàn)文件切片上傳功能的示例代碼

    在實(shí)際開(kāi)發(fā)項(xiàng)目過(guò)程中有時(shí)候需要上傳比較大的文件,然后呢,上傳的時(shí)候相對(duì)來(lái)說(shuō)就會(huì)慢一些,so,后臺(tái)可能會(huì)要求前端進(jìn)行文件切片上傳。本文介紹了Vue實(shí)現(xiàn)文件切片上傳的示例代碼,需要的可以參考一下
    2022-10-10

最新評(píng)論

淳化县| 隆昌县| 广河县| 兰坪| 岫岩| 马山县| 昭通市| 胶南市| 寿阳县| 乳山市| 呈贡县| 缙云县| 崇仁县| 石阡县| 太湖县| 嘉黎县| 崇礼县| 娄烦县| 德格县| 丹凤县| 青海省| 庆云县| 富锦市| 永济市| 廊坊市| 临夏市| 田阳县| 凤翔县| 资中县| 绍兴市| 宝丰县| 曲周县| 德江县| 万山特区| 福海县| 林周县| 蕉岭县| 通化县| 会泽县| 黄浦区| 赣州市|