首页 > 其他 > 详细

路由独享-组件内守卫

时间:2018-10-06 12:34:36      阅读:148      评论:0      收藏:0      [点我收藏+]
路由独享写法:
import VueRouter from ‘vue-router‘
Vue.use(VueRoter)
const router = new VueRouter({
    routes:[
        {path:component:,name:,beforeEnter:((to,next,from)=>{
            alert(‘路由独享-组件内守卫‘)
            next()//跳转
            next(false)//不显示此路由下的组件
        })}
    ],
    mode:‘history‘,
})
组件内守卫:在组件内写
export defalut{
    data(){
        return {
            name:‘tom‘
        }
    },
    beforeRouteEnter((to,from,next)=>{
        //beforeRouteEnter 守卫 不能 访问 this,因为守卫在导航确认前被调用,因此即将登场的新组件还没被创建。
        //可以通过next()回调函数获得组件实例
        next(vm=>{
            vm.name
        })

   })
}

 

路由独享-组件内守卫

原文:https://www.cnblogs.com/chenfan19941111/p/9746918.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!