路由独享-组件内守卫


路由独享写法:
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
        })

   })
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM