问题描述
var content = 'https://mob.baian.com/zhangtiezhi/#/pages/artcle/index?contentId=1630747394385776640'
wx.navigateTo({
url: '/pages/webPage/webPage?href=' +content
})
跳转到webPage页面获取 href参数的时候 只获取到了
https://mob.baian.com/zhangtiezhi/#/pages/artcle/index
?问号后面的内容被截取了
解决方案:
传参前使用 encodeURIComponent进行编码
wx.navigateTo({
url: '/pages/webPage/webPage?href=' + encodeURIComponent(content)
})
webPage页面拿到参数之后 使用 decodeURIComponent()方法进行解码
if (options.href) {
var href = decodeURIComponent(options.href)
this.setData({
href: href
})
}
完美解决问题!