当前位置: 首页 > article >正文

第74讲Breadcrumb 面包屑实现

Breadcrumb 面包屑实现

为了实现二级路由,我们搞成搞个子路由,对于二级菜单

const routes = [
  {
    path: '/',
    name: '首页',
    component: () => import('../views/layout'),
    redirect:'/home',
    children:[
      {
        path: '/home',
        name: '首页',
        component: () => import('../views/home/index')
      },
      {
        path: '/bigType',
        name: '商品大类',
        component: () => import('../views/bigType/index')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login')
  }
]

views/layout/header/breadcrumb.vue

<template>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item v-for="(item,index) in breadcrumbList" :key="index">
      <span class="no-redirect" v-if="index==breadcrumbList.length-1">{{item.name}}</span>
      <span class="redirect" v-else @click="handleRedirect(item.path)">{{item.name}}</span>
    </el-breadcrumb-item>
  </el-breadcrumb>
</template>

<script setup>
import {ref, watch} from 'vue'
import { useRoute,useRouter } from 'vue-router'
const route=useRoute();
const router=useRouter();
console.log(route.matched)

const breadcrumbList=ref([]);


const handleRedirect=(path)=>{
  router.push(path)
}

const initBreadcrumbList=()=>{
  breadcrumbList.value=route.matched;
}

watch(route,()=>{
  initBreadcrumbList();
},{deep:true,immediate:true})

</script>

<style lang="scss" scoped>
.no-redirect{
  cursor:text;
}
.redirect{
  color:#666;
  font-weight:600;
  cursor:pointer;
  &:hover{
    color:#304156
  }
}
</style>

layout index.vue修改:

<template>
  <div class="app-wrapper">
    <el-container>
      <el-aside width="200px" class="sidebar-container"><Menu/></el-aside>
      <el-container>
        <el-header>
          <div class="navbar">
            <Breadcrumb/>
          </div>
        </el-header>
        <el-main>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import Menu from '@/views/layout/menu'
import Breadcrumb from '@/views/layout/header/breadcrumb'
</script>

<style lang="scss" scoped>

.app-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}


.navbar {
  width: 100%;
  height: 60px;
  overflow: hidden;
  background-color: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  padding: 0 16px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  position: relative;
}

:deep(.el-header){
  padding: 0px;
}

.sidebar-container {
  background-color: #2d3a4b;
  height: 100%;
}

:deep(.el-container){
  height: 100%;
}

</style>

在这里插入图片描述
views/home/index.vue

<template>
  后台管理首页
</template>

<script>
export default {
  name: "index"
}
</script>

<style scoped>

</style>

views/bigType/index

<template>
商品大类
</template>

<script>
export default {
  name: "index"
}
</script>

<style scoped>

</style>

http://www.kler.cn/news/234592.html

相关文章:

  • (delphi11最新学习资料) Object Pascal 学习笔记---第4章第4节(函数的高级特性)
  • Acwing---839. 模拟堆
  • H5/CSS 笔试面试考题(71-80)
  • 【LeetCode每日一题】前缀和的例题1248. 统计「优美子数组」974. 和可被 K 整除的子数组
  • 【单片机】简单的自定义延时程序设计(代码演示)
  • CentOS7集群配置免密登录
  • 通过Demo学WPF—数据绑定(二)
  • 基于centos的Linux中如何安装python
  • RK3568笔记十三:Zlmedia推流测试
  • 3秒实现无痛基于Stable Diffusion WebUI安装ComfyUI!无需重复安装环境!无需重复下载模型!安装教程
  • excel 导出 The maximum length of cell contents (text) is 32767 characters
  • C++ 内存管理(newdelete)
  • 渗透专用虚拟机(公开版)
  • [linux c]linux do_div() 函数用法
  • MySQL篇----第十九篇
  • HarmonyOS 开发学习笔记
  • eclipse4.28.0版本如何安装FatJar插件
  • python:xml.etree 生成思维导图 Freemind文件
  • 【HTTP】localhost和127.0.0.1的区别是什么?
  • vue3学习——封装菜单栏
  • lua:有关表访问的metamethod
  • 【DDD】学习笔记-精炼领域分析模型
  • 设计模式-观察者模式 Observer
  • 第77讲用户管理功能实现
  • 指针的基本含义及其用法
  • limit深度分页和优化思路
  • Docker 基本介绍
  • 正则可视化工具:学习和编写正则表达式的利器
  • excel统计分析——成组设计和配对设计
  • 微软 CMU - Tag-LLM:将通用大语言模型改用于专业领域