007_顶部导航栏与左侧导航联动的面包屑实现(vue+element)

本文主要是介绍007_顶部导航栏与左侧导航联动的面包屑实现(vue+element),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

001_顶部导航栏与左侧导航联动的面包屑实现(h3)

  • \src\components\CommonAside.vue
<template><el-menu default-active="2" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b"><!-- 无子级菜单--><el-menu-item :index="item.path" v-for="item in noChildren" :key="item.path" @click="clickMenu(item)"><i :class="'el-icon-' + item.icon"></i><span slot="title">{{ item.label }}</span></el-menu-item><!-- 有子级菜单--><el-submenu index="2" v-for="(item, index) in hasChildren" :key="index"><template slot="title"><i :class="'el-icon-' + item.icon"></i><span>{{ item.label }}</span></template><el-menu-item-group><el-menu-item index="subItem.path" v-for="(subItem, subIndex) in item.children" :key="subIndex" @click="clickMenu(subItem)"><i :class="'el-icon-' + subItem.icon"></i><span>{{ subItem.label }}</span></el-menu-item></el-menu-item-group></el-submenu></el-menu>
</template><script>
export default {computed: {noChildren() {return this.asideMenu.filter(item => !item.children)},hasChildren() {return this.asideMenu.filter(item => item.children)}},data() {//返回一个数组,通过数组的方式循环渲染出来return {asideMenu: [{path: '/',name: 'home',label: '首页',icon: 's-home'},{path: '/task',name: 'task',label: '试验任务',icon: 'document'},{path: '/appointment',name: 'appointment',label: '实验预约',icon: 'date'},{label: '其他',icon: 'user',children: [{path: '/page1',name: 'page1',label: '页面1',icon: 'setting'}]}]}},methods: {clickMenu(item) {this.$store.commit('selectMenu', item)}}
}
</script><style lang="scss" scoped>
.el-menu {//使侧边栏占满屏幕高度height: 100%;border: none;
}
</style>
  • \src\components\CommonHeader.vue
<template><header><div class="l-content"><el-button plain size="mini" icon="el-icon-menu"></el-button><el-breadcrumb separator="/"><el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item><el-breadcrumb-item :to="current.path" v-if="current">{{ current.label }}</el-breadcrumb-item></el-breadcrumb></div><div class="r-conten"><!-- 下拉菜单--><el-dropdown trigger="click"><span class="el-dropdown-link"><img :src="userImg" class="user"/></span><el-dropdown-menu slot="dropdown"><el-dropdown-item>个人中心</el-dropdown-item><el-dropdown-item>退出</el-dropdown-item></el-dropdown-menu></el-dropdown></div></header>
</template><script>
import { mapState } from 'vuex'
export default {computed: {...mapState({current: state => state.tab.currentMenu})},data() {return {//以模块的方式引入,而不是字符串userImg: require('../assets/images/1.png')}}
}
</script><style lang="scss" scoped>
header {display: flex;height: 100%;align-items: center;//justify-content 用于设置或检索弹性盒子元素在主轴(横轴)方向上的对齐方式。justify-content: space-between;
}
.l-content {display: flex;align-items: center;.el-button {margin-right: 20px;}
}
.r-conten {.user {width: 40px;height: 40px;border-radius: 30%;}
}
</style>
<!-- 组件嵌套在逐渐里面的样式 不能scoped-->
<style lang="scss">
.el-breadcrumb__item {.el-breadcrumb__inner {color: #666666;font-weight: normal;}&:last-child {.el-breadcrumb__inner {color: #ffffff;}}
}
</style>
  • \src\store\index.js
import Vue from 'vue'
import Vuex from 'vuex'//导入模块
import student from './student'
import tab from './tab'Vue.use(Vuex)export default new Vuex.Store({state: {},mutations: {},actions: {},modules: {student,tab}
})
  • \src\store\tab.js
export default {state: {currentMenu: null,menu: []},//同步修改state里面的值mutations: {selectMenu(state, val) {if (val.name !== 'home') {state.currentMenu = val} else {state.currentMenu = null}}},modules: {}
}
  • 浏览器界面

这篇关于007_顶部导航栏与左侧导航联动的面包屑实现(vue+element)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/826420

相关文章

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

SpringBoot中使用Flux实现流式返回的方法小结

《SpringBoot中使用Flux实现流式返回的方法小结》文章介绍流式返回(StreamingResponse)在SpringBoot中通过Flux实现,优势包括提升用户体验、降低内存消耗、支持长连... 目录背景流式返回的核心概念与优势1. 提升用户体验2. 降低内存消耗3. 支持长连接与实时通信在Sp

Conda虚拟环境的复制和迁移的四种方法实现

《Conda虚拟环境的复制和迁移的四种方法实现》本文主要介绍了Conda虚拟环境的复制和迁移的四种方法实现,包括requirements.txt,environment.yml,conda-pack,... 目录在本机复制Conda虚拟环境相同操作系统之间复制环境方法一:requirements.txt方法

Spring Boot 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

springboot下载接口限速功能实现

《springboot下载接口限速功能实现》通过Redis统计并发数动态调整每个用户带宽,核心逻辑为每秒读取并发送限定数据量,防止单用户占用过多资源,确保整体下载均衡且高效,本文给大家介绍spring... 目录 一、整体目标 二、涉及的主要类/方法✅ 三、核心流程图解(简化) 四、关键代码详解1️⃣ 设置

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F

CSS实现元素撑满剩余空间的五种方法

《CSS实现元素撑满剩余空间的五种方法》在日常开发中,我们经常需要让某个元素占据容器的剩余空间,本文将介绍5种不同的方法来实现这个需求,并分析各种方法的优缺点,感兴趣的朋友一起看看吧... css实现元素撑满剩余空间的5种方法 在日常开发中,我们经常需要让某个元素占据容器的剩余空间。这是一个常见的布局需求

CSS Anchor Positioning重新定义锚点定位的时代来临(最新推荐)

《CSSAnchorPositioning重新定义锚点定位的时代来临(最新推荐)》CSSAnchorPositioning是一项仍在草案中的新特性,由Chrome125开始提供原生支持需... 目录 css Anchor Positioning:重新定义「锚定定位」的时代来了! 什么是 Anchor Pos