使用场景
1.获取推广人ID:
用户A分享给商品详情链接刚给用户B,用户B下单后,订单会记录用户A的佣金,就需要在商品分享给链接记录分享人即“推广人ID”。
方式一:
window.location.href
1.当前URL
window.location.href
结果:http://www.myurl.com:8866/test?id=123&username=xxx
2.协议
window.location.protocol
结果:http
3.域名 + 端口
window.location.host
结果:www.myurl.com:8866
4.域名
window.location.hostname()
结果:www.myurl.com
5.端口
window.location.port()
结果:8866
6.路径部分
window.location.pathname()
结果:/test
7.请求的参数
window.location.search
结果:?id=123&username=xxx
方式二:使用
onLoad(options) {
// 获取url路由参数
var launchOptions = uni.getLaunchOptionsSync()
console.log("goodsDetail onLoad launchOptions", launchOptions.query)
// 存储分享者微信openID
uni.setStorageSync("sharerInfo", launchOptions.query)
},