el-menu与el-breadcrumb联动
时间: 2023-11-22 08:33:07 浏览: 34
的原理是什么?
El-menu和El-breadcrumb在联动时,实际上是通过路由来进行绑定的。El-menu需要设置router属性,以便根据不同的路由显示不同的菜单选项。El-breadcrumb则根据当前路由动态生成面包屑导航。因此,只要在路由配置中正确设置各组件的路由关系,就可以实现联动。
相关问题
el-breadcrumb-item
El componente el-breadcrumb-item es parte del conjunto de componentes del framework de Vue.js, Element UI.
Este componente se utiliza dentro del componente el-breadcrumb para definir cada uno de los elementos del breadcrumb.
Algunas de las propiedades que se pueden definir en el-breadcrumb-item son:
- to: la ruta a la que se redirige cuando se hace clic en el enlace del breadcrumb.
- replace: si es true, la ruta se reemplaza en lugar de añadir una nueva entrada al historial de navegación.
- target: el nombre de la ventana o marco donde se abrirá la ruta de destino.
- separator: el separador que se muestra entre los elementos del breadcrumb.
Ejemplo de uso:
<el-breadcrumb separator="/">
<el-breadcrumb-item :to="{ path: '/' }">Inicio</el-breadcrumb-item>
<el-breadcrumb-item :to="{ path: '/foo' }">Foo</el-breadcrumb-item>
<el-breadcrumb-item :to="{ path: '/foo/bar' }">Bar</el-breadcrumb-item>
</el-breadcrumb>
el-breadcrumb-item样式更改
el-breadcrumb-item样式更改可以通过修改CSS样式表来实现。可以使用以下代码来更改el-breadcrumb-item的样式:
```
/* 不被选中时的颜色 */
.el-breadcrumb ::v-deep .el-breadcrumb__inner {
color: #d9bb95 !important;
font-weight: 400 !important;
}
/* 被选中时的颜色 */
.el-breadcrumb__item:last-child ::v-deep .el-breadcrumb__inner {
color: #fc9105 !important;
font-weight: 800 !important;
}
```
其中,`::v-deep`是一个CSS伪元素,用于选择所有后代元素,包括跨越组件边界的后代元素。这样,我们就可以选择el-breadcrumb和el-breadcrumb-item组件中的元素,并修改它们的样式。在上面的代码中,我们使用了`color`和`font-weight`属性来更改字体颜色和字体粗细。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<template> <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb"> <el-breadcrumb-item>首页</el-breadcrumb-item> <el-breadcrumb-item v-for="bread in breadList" v-bind:key="bread"> {{ breadsName[bread] }} </el-breadcrumb-item> </el-breadcrumb> </template> <script lang="ts"> import { Provide, Component, Watch, Prop, Vue } from 'vue-property-decorator'; @Component export default class BreadCrumb extends Vue { @Provide() private breadsName: { [index: string]: string } = { '1': 'title1', '1-1': 'title1-1', '1-2': 'title1-2', '1-3': 'title1-3', }; @Provide() private breadList: string[] = []; private created() { this.getBreadList(); } @Watch('$route') private getBreadList() { this.breadList = []; for (const routeInfo of this.$route.matched) { if (typeof routeInfo.name === 'string' && routeInfo.name !== 'home') { this.breadList.push(routeInfo.name); } } } } </script> <style lang="less"> .breadcrumb { margin-bottom: 20px; } </style>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)