Vue基于el-breadcrumb實(shí)現(xiàn)面包屑功能(操作代碼)
vue3 + elementPlus 實(shí)現(xiàn)面包屑功能
文章后面附效果圖
數(shù)據(jù)結(jié)構(gòu)
首先展示一下數(shù)據(jù)基礎(chǔ)結(jié)構(gòu)
紅色框框是默認(rèn)存在的數(shù)據(jù),其他數(shù)據(jù)就是通過選中側(cè)邊欄菜單進(jìn)行數(shù)據(jù)插入
關(guān)鍵數(shù)據(jù)字段為 path, meta
準(zhǔn)備側(cè)邊欄
首先需要自己準(zhǔn)備一個(gè)側(cè)邊欄這邊就不進(jìn)行講解,上個(gè)效果圖
實(shí)現(xiàn)面包屑代碼
<template> // 面包屑組件, separator為分割線,具體可以去elementPlus官網(wǎng)查看 <el-breadcrumb separator="/"> <div class="breadcrumb-content"> // 動(dòng)畫組件 [官網(wǎng)鏈接](https://cn.vuejs.org/guide/built-ins/transition.html) <transition-group name="breadcrumb"> <el-breadcrumb-item class="breadcrumb-item" v-for="item in arr.breadCrumbList" :key="item.path"> <span v-if="item.redirect === route.path"> {{ item.meta.title }} </span> <a v-else @click="handleLine(item)">{{ item.meta.title }}</a> </el-breadcrumb-item> </transition-group> </div> </el-breadcrumb> </template> <script setup lang="ts"> const router = useRouter(); // 面包屑數(shù)據(jù) let arr = reactive({ breadCrumbList: [], }); const route = useRoute(); // 獲取面包屑數(shù)據(jù) const getBreadcrumbList = () => { arr.breadCrumbList = []; route.matched.forEach((item) => { if (item.meta.title) arr.breadCrumbList.push(item); }); // 判斷是否存在首頁默認(rèn)數(shù)據(jù),不存在就插入到數(shù)據(jù)首位 if (!arr.breadCrumbList.length || arr.breadCrumbList[0].name !== "Dashboard") arr.breadCrumbList.unshift({ path: "/dashboard/index", meta: { title: "首頁" }, }); }; getBreadcrumbList(); // 監(jiān)聽路由變化 watch(route, () => { getBreadcrumbList(); }); // 面包屑跳轉(zhuǎn) const handleLine = ({ redirect, path }) => { redirect ? router.push(redirect) : router.push(path); }; </script> <style lang="less" scoped> .el-breadcrumb { display: flex; padding-left: 10px; line-height: 50px; background-color: #f6f6f6; } .breadcrumb-item { margin-left: 8px; } .breadcrumb-content { position: relative; } .breadcrumb-enter-active, .breadcrumb-leave-active { transition: all 0.5s; } .breadcrumb-enter-from, .breadcrumb-leave-active { opacity: 0; } .breadcrumb-move { transition: all 0.5s; } .breadcrumb-leave-active { position: absolute; right: -50px; } </style>
效果圖
到此這篇關(guān)于Vue基于el-breadcrumb實(shí)現(xiàn)面包屑功能的文章就介紹到這了,更多相關(guān)vue面包屑內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue實(shí)現(xiàn)導(dǎo)出word文檔功能實(shí)例(含多張圖片)
項(xiàng)目需要導(dǎo)出word,于是乎又是查閱資料,然后自己寫,下面這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)導(dǎo)出word文檔功能(含多張圖片)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09記一次Vue中$route序列號(hào)報(bào)錯(cuò)
本文主要介紹了記一次Vue中$route序列號(hào)報(bào)錯(cuò),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04vuex(vue狀態(tài)管理)的特殊應(yīng)用案例分享
Vuex 是一個(gè)專為 Vue.js 應(yīng)用程序開發(fā)的狀態(tài)管理模式。它采用集中式存儲(chǔ)管理應(yīng)用的所有組件的狀態(tài),并以相應(yīng)的規(guī)則保證狀態(tài)以一種可預(yù)測的方式發(fā)生變化。2020-03-03Vite3 Svelte3構(gòu)建Web應(yīng)用報(bào)錯(cuò)process is not def
這篇文章主要介紹了Vite3 Svelte3構(gòu)建Web應(yīng)用報(bào)錯(cuò):'process is not defined'解決方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06vue使用?vue-socket.io三種方式及踩坑實(shí)例解析
這篇文章主要為大家介紹了vue使用?vue-socket.io三種方式及踩坑實(shí)例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09