beforeRouteEnter(to,from,next){
// 导航进入组件时调用
// 不能获取实例this,因为当组件执行时,组件实例还没有被创建
console.log('beforeRouter');
console.log(this); //undefined
console.log(to); //{fullPath: "/routerPratice",path: "/routerPratice",meta: {}...},要跳到哪个页面,并将页面信息呈现
console.log(from); // {fullPath: "/",path: "/",meta: {}...},来自哪个页面,并将页面信息呈现
// next(false); //阻止跳转
next(); //可以跳转
},
beforeRouteLeave (to, from, next) {
// 导航离开该组件的对应路由时调用
// 可以访问组件实例 `this`
console.log('beforeRouteLeave');
console.log(this); //VueComponent
console.log(to); //{name: "routerPratice2", meta: {…}, path: "/routerPratice2", hash: "", query: {…}, …} 要跳到哪个页面,并将页面信息呈现
console.log(from); //来自哪个页面,并将页面信息呈现
// next(false); //阻止跳转
next(); //可以跳转
},
vue beforeRouteEnter && beforeRouteLeave
最新推荐文章于 2024-06-19 16:58:40 发布