欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

引言

后臺管理系統(tǒng)中,經(jīng)常會出現(xiàn)需要面包屑的情況,但是又不想每個頁面都實(shí)現(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ù)項(xiàng)目修改

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

相關(guān)文章

  • Vue使用v-viewer插件實(shí)現(xiàn)圖片預(yù)覽和縮放和旋轉(zhuǎn)等功能(推薦)

    Vue使用v-viewer插件實(shí)現(xiàn)圖片預(yù)覽和縮放和旋轉(zhuǎn)等功能(推薦)

    v-viewer是一個基于viewerjs封裝的vue圖片預(yù)覽組件,有預(yù)覽縮放拉伸旋轉(zhuǎn)切換拖拽等功能,支持配置化,這篇文章主要介紹了Vue使用v-viewer插件實(shí)現(xiàn)圖片預(yù)覽和縮放和旋轉(zhuǎn)等功能,需要的朋友可以參考下
    2023-02-02
  • Vue項(xiàng)目引用百度地圖并實(shí)現(xiàn)搜索定位等功能(案例分析)

    Vue項(xiàng)目引用百度地圖并實(shí)現(xiàn)搜索定位等功能(案例分析)

    這篇文章主要介紹了Vue項(xiàng)目引用百度地圖并實(shí)現(xiàn)搜索定位等功能(案例分析),本篇文章為案例分析,技術(shù)點(diǎn)較多,所以篇幅較長,認(rèn)真閱覽的你一定會學(xué)到很多知識,需要的朋友可以參考下
    2022-09-09
  • 詳解Vue如何實(shí)現(xiàn)響應(yīng)式布局

    詳解Vue如何實(shí)現(xiàn)響應(yīng)式布局

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)響應(yīng)式布局的兩種方法,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以跟隨小編一起了解一下
    2023-12-12
  • Vue?全部生命周期組件梳理整理

    Vue?全部生命周期組件梳理整理

    這篇文章主要介紹了Vue?全部生命周期組件梳理整理,在創(chuàng)建組件之前使用;在實(shí)例初始化之后,進(jìn)行數(shù)據(jù)偵聽和事件,偵聽器的配置之前同步調(diào)用
    2022-06-06
  • Vue頁面跳轉(zhuǎn)傳遞參數(shù)及接收方式

    Vue頁面跳轉(zhuǎn)傳遞參數(shù)及接收方式

    這篇文章主要介紹了Vue頁面跳轉(zhuǎn)傳遞參數(shù)及接收方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue-cli-service serve報(bào)錯error:0308010C:digital envelope routines::unsupported

    vue-cli-service serve報(bào)錯error:0308010C:digital enve

    這篇文章主要介紹了vue-cli-service serve報(bào)錯error:0308010C:digital envelope routines::unsupported的解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • vue router 跳轉(zhuǎn)時打開新頁面的示例方法

    vue router 跳轉(zhuǎn)時打開新頁面的示例方法

    這篇文章主要介紹了vue router 跳轉(zhuǎn)時打開新頁面的示例方法,本文通過示例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-07-07
  • vue自定義加載指令v-loading占位圖指令v-showimg

    vue自定義加載指令v-loading占位圖指令v-showimg

    這篇文章主要為大家介紹了vue自定義加載指令和v-loading占位圖指令v-showimg的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • vue3接口數(shù)據(jù)賦值對象,渲染報(bào)錯問題及解決

    vue3接口數(shù)據(jù)賦值對象,渲染報(bào)錯問題及解決

    這篇文章主要介紹了vue3接口數(shù)據(jù)賦值對象,渲染報(bào)錯問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue之Pinia狀態(tài)管理

    Vue之Pinia狀態(tài)管理

    這篇文章主要介紹了Vue中Pinia狀態(tài)管理,Pinia開始于大概2019年,其目的是設(shè)計(jì)一個擁有 組合式 API 的 Vue 狀態(tài)管理庫,Pinia本質(zhì)上依然是一個狀態(tài)管理庫,用于跨組件、頁面進(jìn)行狀態(tài)共享,感興趣的同學(xué)可以參考閱讀
    2023-04-04

最新評論