Vue获取上个路由

mac2024-05-23  32

使用钩子函数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 官网文档

最新回复(0)