微信小程序怎么实现跳转外链,且外链带参

1.现象:
参数是链接带参数:
”http://wq.chayingwh.com/app/index.php?i=18&c=entry&m=ewei_shopv2&do=mobile&r=goods.detail&id=246”跳转到另外一个页面,接收到的链接是”http://wq.chayingwh.com/app/index.php”,无法接收到链接后面的参数
微信小程序怎么实现跳转外链,且外链带参_第1张图片
2.解决方案:在跳转页面对链接参数进行编码,在接收参数页面对链接参数进行解码
在这里插入图片描述
3.例子

页面1 /pages/index/index

  <view bindtap=’goOutlink’></view>

   goOutlink:function(e){
     
     let  linkUrl=”http://wq.chayingwh.com/app/index.php?i=18&c=entry&m=ewei_shopv2&do=mobile&r=goods.detail&id=246”

    wx.navigate({
     
        url;/pages/reward_linkUrl/reward_linkUrl?linkUrl'+encodeURIComponent(linkUrl)
})
}

页面2 /pages/reward_linkUrl/reward_linkUrl

<web-view src={
     {
     linkUrl}}}></web-view>

data:{
     
   LinkUrl:’https://www.baidu.com/}

onLoad:function(options){
     
     console.log(options)
     console.log(options.linkUrl)
     console.log(decodeURIComponent(options.linkUrl))
     this.setData({
     
         LinkUrl:decodeURIComponent(options.linkUrl)
     })
}

总结:
对URL进行编码解码的应用场景:
1.接收传参出现中英文乱码场景
2.参数是链接带参数

java
编码:URLEncode.encode(URL.”UTF-8”),解码:URLDecode.decode(URL,”UTF-8”)

php
编码:urlencode(url) 解码:urldecode(url)

python
from urllib.parse import unquote,quote
编码:quote(url) 解码:unquote(url)

javascript
1.编码:encodeURI(url) 解码: decodeURI(url)
2.编码:escape(url) 解码:unescape(url)
3.编码:encodeURIComponent(url) 解码:decodeURIComponent(url)

你可能感兴趣的:(前端,JS,小程序,java,php,python)