解决vue路由跳转同一页面,携带不同参数,页面不刷新的问题

携带不同的参数跳转到同一路由,页面报错不刷新,

解决报错:

//相同路由跳转报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

页面不刷新
使用watch方法监听路由对象

watch:{
  '$route'(to,from){
    this.$api.userApi.userInfo({id:this.$route.query.userId}).then(value => {
      this.userInfolist=value.result
    })
  }  
},
  created() {
    console.log("hah"+this.$route.query.userId)
    this.$api.userApi.userInfo({id:this.$route.query.userId}).then(value => {
     this.userInfolist=value.result
    })
  }
}

版权声明:本文为m0_46692587原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。