在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 中。就這樣,調整一下生命周期函數也就解決了。