最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

vue2.0 elementUI制作面包屑导航栏

来源:懂视网 责编:小采 时间:2020-11-27 22:19:11
文档

vue2.0 elementUI制作面包屑导航栏

vue2.0 elementUI制作面包屑导航栏:Main.js var routeList = []; router.beforeEach((to, from, next) => { var index = -1; for(var i = 0; i < routeList.length; i++) { if(routeList[i].name == to.name) { index = i; break; } } if (index !== -1) { //如果存在路由列表,则把之后的路由都删掉 routeL
推荐度:
导读vue2.0 elementUI制作面包屑导航栏:Main.js var routeList = []; router.beforeEach((to, from, next) => { var index = -1; for(var i = 0; i < routeList.length; i++) { if(routeList[i].name == to.name) { index = i; break; } } if (index !== -1) { //如果存在路由列表,则把之后的路由都删掉 routeL

Main.js

var routeList = [];
router.beforeEach((to, from, next) => {
 var index = -1;
 for(var i = 0; i < routeList.length; i++) {
 if(routeList[i].name == to.name) {
 index = i;
 break;
 }
 }
 if (index !== -1) {
//如果存在路由列表,则把之后的路由都删掉
 routeList.splice(index + 1, routeList.length - index - 1);
 } else if(to.name != '登录'){
 routeList.push({"name":to.name,"path":to.fullPath});
 }
 to.meta.routeList = routeList;
 next()
});

2、在要使用的组件中

<template>
 <div class="level-bread">
 <el-breadcrumb separator="/">
 <el-breadcrumb-item v-for="item in realList" :to="item.path">{{item.name}}</el-breadcrumb-item>
 </el-breadcrumb>
 </div>
</template>

<script>
 export default {
 name: "lelve-bread",
 created(){
 this.getRoutePath();
 },
 data() {
 return {
 realList: []
 }
 },
 methods:{
 getRoutePath() {
 this.realList = this.$route.meta.routeList;
 }
 },
 beforeRouteEnter(to,from, next) {
 next((vm) => {
 vm.realList = to.meta.routeList;
 });
 },
 // watch:{
 // $route:function(newV,oldV) {
 // this.realList =newV.meta.routeList;
 // }
 // }
 }
</script>

用 watch 或者 beforeRouteEnter 均可。

需要注意的是,beforeRouteEnter 此时访问不到this。

const Foo = {
 template: `...`,
 beforeRouteEnter (to, from, next) {
 // 在渲染该组件的对应路由被 confirm 前调用
 // 不!能!获取组件实例 `this`
 // 因为当守卫执行前,组件实例还没被创建
 },
 beforeRouteUpdate (to, from, next) {
 // 在当前路由改变,但是该组件被复用时调用
 // 举例来说,对于一个带有动态参数的路径 /foo/:id,在 /foo/1 和 /foo/2 之间跳转的时候,
 // 由于会渲染同样的 Foo 组件,因此组件实例会被复用。而这个钩子就会在这个情况下被调用。
 // 可以访问组件实例 `this`
 },
 beforeRouteLeave (to, from, next) {
 // 导航离开该组件的对应路由时调用
 // 可以访问组件实例 `this`
 }
}

文档

vue2.0 elementUI制作面包屑导航栏

vue2.0 elementUI制作面包屑导航栏:Main.js var routeList = []; router.beforeEach((to, from, next) => { var index = -1; for(var i = 0; i < routeList.length; i++) { if(routeList[i].name == to.name) { index = i; break; } } if (index !== -1) { //如果存在路由列表,则把之后的路由都删掉 routeL
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top