小程序页面跳转传参参数值为url时参数丢失

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014094101/article/details/81047083

当参数的值为url的时候,在options中的值没有参数“?”之后字符串被截取。
*例如:

let url="http://baidu.com/?a=1&b=2"
wx.navigateTo({
url: `detail?url=${url}`
})

可以使用encodeURIComponent():函数可把字符串作为 URI 组件进行编码。

let url=encodeURIComponent("http://baidu.com/?a=1&b=2")
wx.navigateTo({
url: `detail?url=${url}`
})

在获取的时候decodeURIComponent(options.url)

猜你喜欢

转载自blog.csdn.net/u014094101/article/details/81047083