mpvue路由传参报错Cannot read property 'query' of undefined

  在mpvue编写的小程序项目中,页面跳转间我希望通过编程式导航传递些参数

  • 传参页面代码:  
this.$router.push({path:'/pages/login/changePassword/main',query:{phone:this.phoneNumber,code:this.verificationCode}})
  • 接参页面代码:
created () {
    this.phoneNumber = this.$route.query.phone
    this.verificationCode = this.$route.query.code
}

  

  按照vue的方式来看上面的代码不应该有什么问题,但是在mpvue中就有了如下的报错:

  

 

   

  再说一下解决办法:

  接参页面获取参数的代码不能写在生命周期函数  created  中,而应该写在 mounted 中。就这样,调整一下生命周期函数也就解决了。  

 

posted @ 2020-02-28 10:02  刘彤彤  阅读(4011)  评论(0编辑  收藏  举报