web-view url无法携带参数问题 Published on Mar 27, 2025 in 随笔 with 0 comment 解决方案: 使用encodeURIComponent()编码,decodeURIComponent()解码 我们都知道小程序在跳转外链时只能通过web-view跳转 如果链接是在A页面请求到,传递到B页面中赋值给src,就容易出现参数丢失的现象 //A页面 src = 'https://www.example.com?id=3' uni.uni.navigateTo({ url: `/home/B?url=${src}` }) //B页面 onLoad(e){ this.url = e.url } //此时的url = 'https://www.example.com' ?后边的参数丢失 一直跳转出错,后来才发现地址中参数丢失,?后面的参数丢失 解决方法: 传递地址时使用encodeURIComponent()编码,decodeURIComponent()解码 //A页面 src = 'https://www.example.com?id=3' uni.uni.navigateTo({ url: `/home/B?url=${encodeURIComponent(src)}` }) //B页面 onLoad(e){ this.url = decodeURIComponent(e.url) } 这样传递过来的地址参数不会丢失 本文由 admin 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。