vue beforeRouteEnter && beforeRouteLeave

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();  //可以跳转
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值