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

vue+elementUI實現(xiàn)動態(tài)面包屑

 更新時間:2022年04月12日 14:20:46   作者:寫B(tài)ug的大雄  
這篇文章主要為大家詳細(xì)介紹了vue+elementUI實現(xiàn)動態(tài)面包屑,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue+elementUI實現(xiàn)動態(tài)面包屑的具體代碼,供大家參考,具體內(nèi)容如下

引言

后臺管理系統(tǒng)中,經(jīng)常會出現(xiàn)需要面包屑的情況,但是又不想每個頁面都實現(xiàn)一個,這樣不方便維護(hù),因此封裝了面包屑組件,方便在頁面使用

封裝組件

<!-- Breadcrumb/index.vue --> ? ?
<template>
? <div>
? ? <el-breadcrumb class="breadcrumb" separator="/">
? ? ? <transition-group name="breadcrumb">
? ? ? ? <el-breadcrumb-item v-for="(item, index) in breadList" :key="item.path">
? ? ? ? ? <span
? ? ? ? ? ? v-if="
? ? ? ? ? ? ? item.redirect === $route.path || index == breadList.length - 1
? ? ? ? ? ? "
? ? ? ? ? >
? ? ? ? ? ? {{ item.meta.title }}
? ? ? ? ? </span>
? ? ? ? ? <a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
? ? ? ? </el-breadcrumb-item>
? ? ? </transition-group>
? ? </el-breadcrumb>
? </div>
</template>

<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
? data () {
? ? return {
? ? ? // 路由集合
? ? ? breadList: [] as any[]
? ? };
? },
? methods: {
? ? // 判斷是否包含首頁路由
? ? isDashboard (route: { name: string }) {
? ? ? const name = route && route.name;
? ? ? if (!name) {
? ? ? ? return false;
? ? ? }
? ? ? return route.name === 'Dashboard';
? ? },
? ? // 面包屑跳轉(zhuǎn)
? ? handleLink (item: { redirect: any; path: any }) {
? ? ? const { redirect, path } = item;
? ? ? redirect ? this.$router.push(redirect) : this.$router.push(path);
? ? },
? ? // 判斷當(dāng)前面包屑
? ? init () {
? ? ? this.breadList = [];
? ? ? this.$route.matched.forEach((item) => {
? ? ? ? if (item.meta.title) {
? ? ? ? ? this.breadList.push(item);
? ? ? ? }
? ? ? });

? ? ? if (!this.isDashboard(this.breadList[0])) {
? ? ? ? this.breadList.unshift({
? ? ? ? ? path: '/dashboard/index',
? ? ? ? ? meta: { title: '首頁' }
? ? ? ? });
? ? ? }
? ? }
? },
? created () {
? ? this.init();
? },
? // 當(dāng)組件放在總布局組件中,需要監(jiān)聽路由變化
? watch: {
? ? $route () {
? ? ? this.init();
? ? }
? }
});
</script>

<style lang="less" scoped>
.breadcrumb-enter-active,
.breadcrumb-leave-active {
? transition: all 0.5s;
}

.breadcrumb-enter,
.breadcrumb-leave-active {
? opacity: 0;
? transform: translateX(20px);
}

.breadcrumb-move {
? transition: all 0.5s;
}

.breadcrumb-leave-active {
? position: absolute;
}
</style>

頁面使用

<template>
? <div>
? ? <my-breadcrumb></my-breadcrumb>
? ? four
? </div>
</template>

<script lang="ts">
import Vue from 'vue';
import MyBreadcrumb from '@/components/Breadcrumb/index.vue';

export default Vue.extend({
? components: {
? ? MyBreadcrumb
? }
});
</script>

<style scoped>
</style>

路由文件參考

// router/index.ts

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 表示是否只有一級權(quán)限,只出現(xiàn)在只有一個子集,沒有其他孫子集
?* 當(dāng)權(quán)限擁有多個子集或者孫子集,一級權(quán)限需要加上 meta
?* 二級權(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: '首頁',
? ? ? ? ? icon: 'el-icon-location'
? ? ? ? }
? ? ? }
? ? ]
? }
];

// 動態(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: '二級導(dǎo)航',
? ? ? ? ? role: 'two',
? ? ? ? ? icon: 'el-icon-location'
? ? ? ? },
? ? ? ? children: [
? ? ? ? ? {
? ? ? ? ? ? path: 'three',
? ? ? ? ? ? name: 'Three',
? ? ? ? ? ? component: () => import('@/views/editor/three.vue'),
? ? ? ? ? ? meta: {
? ? ? ? ? ? ? title: '三級導(dǎo)航',
? ? ? ? ? ? ? role: 'three',
? ? ? ? ? ? ? icon: 'el-icon-location'
? ? ? ? ? ? }
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? path: 'four',
? ? ? ? ? ? name: 'Four',
? ? ? ? ? ? component: () => import('@/views/editor/four.vue'),
? ? ? ? ? ? meta: {
? ? ? ? ? ? ? title: '三級導(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: '樹狀圖',
? ? ? ? ? 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'
? ? ? ? }
? ? ? }
? ? ]
? }
];

// 出錯跳轉(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;

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解vue-router 2.0 常用基礎(chǔ)知識點之導(dǎo)航鉤子

    詳解vue-router 2.0 常用基礎(chǔ)知識點之導(dǎo)航鉤子

    本篇文章主要介紹了vue-router 2.0 常用基礎(chǔ)知識點之導(dǎo)航鉤子,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 使用WebStorm導(dǎo)入已有Vue項目并運行的詳細(xì)步驟與注意事項

    使用WebStorm導(dǎo)入已有Vue項目并運行的詳細(xì)步驟與注意事項

    這篇文章主要介紹了如何使用WebStorm導(dǎo)入、運行和管理Vue項目,包括環(huán)境配置、Node.js和npm版本管理、項目依賴管理以及常見問題的解決方案,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-11-11
  • vue使用Luckysheet插件實現(xiàn)excel導(dǎo)入導(dǎo)出

    vue使用Luckysheet插件實現(xiàn)excel導(dǎo)入導(dǎo)出

    本文主要介紹了vue使用Luckysheet插件實現(xiàn)excel導(dǎo)入導(dǎo)出,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-03-03
  • vue項目實現(xiàn)自定義滑塊過渡效果

    vue項目實現(xiàn)自定義滑塊過渡效果

    這篇文章主要介紹了vue項目實現(xiàn)自定義滑塊過渡效果,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • vue在圖片上傳的時候壓縮圖片

    vue在圖片上傳的時候壓縮圖片

    這篇文章主要介紹了vue在圖片上傳的時候壓縮圖片,幫助大家緩解服務(wù)器壓力,提高程序性能,感興趣的朋友可以了解下
    2020-11-11
  • vue中動態(tài)控制btn的disabled屬性方式

    vue中動態(tài)控制btn的disabled屬性方式

    這篇文章主要介紹了vue中動態(tài)控制btn的disabled屬性方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vue Element前端應(yīng)用開發(fā)之開發(fā)環(huán)境的準(zhǔn)備工作

    Vue Element前端應(yīng)用開發(fā)之開發(fā)環(huán)境的準(zhǔn)備工作

    這篇文章主要介紹了Vue Element前端應(yīng)用開發(fā)之開發(fā)環(huán)境的準(zhǔn)備工作,對Vue感興趣的同學(xué),可以來學(xué)習(xí)一下
    2021-05-05
  • Vue組件data函數(shù)的具體使用

    Vue組件data函數(shù)的具體使用

    在Vue組件中,data函數(shù)用于定義組件的數(shù)據(jù),本文主要介紹了Vue組件data函數(shù)的具體使用,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-02-02
  • vue如何給頁面增加url前綴

    vue如何給頁面增加url前綴

    這篇文章主要介紹了vue如何給頁面增加url前綴問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • vue v-model的用法解析

    vue v-model的用法解析

    這篇文章主要介紹了v-model的基本用法解析,幫助大家更好的理解和學(xué)習(xí)vue v-model的使用方法,感興趣的朋友可以了解下
    2020-10-10

最新評論

合阳县| 年辖:市辖区| 连城县| 桐梓县| 深泽县| 云龙县| 昌吉市| 巩留县| 元阳县| 康乐县| 平泉县| 龙州县| 敖汉旗| 安仁县| 射洪县| 临泉县| 满洲里市| 天峻县| 疏附县| 高淳县| 澄江县| 航空| 于都县| 富宁县| 大连市| 临颍县| 偏关县| 信丰县| 寿宁县| 鄱阳县| 鲁山县| 宁陕县| 甘孜| 将乐县| 麻栗坡县| 崇礼县| 泾源县| 洛浦县| 敦煌市| 普兰店市| 平乐县|