Vue获取上个路由

使用钩子函数beforeRouteEnter

beforeRouteEnter(to, from, next) {
		console.log('beforeRouteEnter第一个参数to',to);
    	console.log('beforeRouteEnter第二个参数from',from);
   		 console.log('beforeRouteEnter第三个参数next',next);
        // 如果是从添加乘客页面跳转过来,则从缓存中取乘客数据,如果是从选择航班页面过来,则清除乘客缓存
        if(from.name === 'CabinList'){
            sessionStorage.removeItem('passengerList')
        }
        next(vm => {
            //因为当钩子执行前,组件实例还没被创建
            // vm 就是当前组件的实例相当于上面的 this,所以在 next 方法里你就可以把 vm 当 this 来用了。
            //当前组件的实例
        });
    },

在这里插入图片描述
更多路由相关操作:Vue-Route 官网文档

发布了62 篇原创文章 · 获赞 33 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/Silence_Sep/article/details/102839915
今日推荐