本文主要和大家分享vue 2.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) {//如果存在路由列表,则把之后的路由都删掉 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、在要使用的组件中
{{item.name}}
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; // } // } }
登录后复制
使用 watch 或者 beforeRouteEnter 均可。
需要注意的是,beforeRouteEnter 此时访问不到this。
官网描述 https://router.vuejs.org/zh-c…
立即学习“前端免费学习笔记(深入)”;
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` }}
登录后复制
相关推荐:
微信小程序导航栏选项卡效果的实现方法
layui导航栏实现代码
jquery和css实现侧边导航栏效果示例代码
以上就是vue 2.0和elementUI实现面包屑导航栏方法代码的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2786344.html