首页 > 其他 > 详细

组件内导航之beforeRouteUpdate的使用

时间:2019-05-08 13:51:48      阅读:564      评论:0      收藏:0      [点我收藏+]

使用场景:

  组件复用;路由跳转;

beforeRouteUpdate (to, from, next) {
    // 在当前路由改变,但是该组件被复用时调用
    // 举例来说,对于一个带有动态参数的路径 /foo/:id,在 /foo/1 和 /foo/2 之间跳转的时候,
    // 由于会渲染同样的 Foo 组件,因此组件实例会被复用。而这个钩子就会在这个情况下被调用。
    // 可以访问组件实例 `this`
  },

 

export default{
   data(){
         return {}
  },
   beforeRouteUpdate(to,from,next){
        console.log(to,from,next)
        if(to.fullPath!=from.fullPath){
            next()
            this.changeUser()
        }
    },
    methods:{
         changeUser(){
            getUserBaseInfo({userId:this.$route.params.id}).then(res=>{
            if(res.success){
                this.stuInfo = res.data;
            }else{
                this.$message.error(res.message)
            }
            
        })
        }  
    }  
}

 

组件内导航之beforeRouteUpdate的使用

原文:https://www.cnblogs.com/zmdblog/p/10831297.html

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