Vue gets url parameters

scenes to be used

1. Get Promoter ID:

User A shares the product details link to user B. After user B places an order, the order will record user A's commission, and it is necessary to record the sharer's "promoter ID" in the product sharing link.

method one:

window.location.href

1. Current URL

window.location.href

结果:http://www.myurl.com:8866/test?id=123&username=xxx

2. Agreement

window.location.protocol

结果:http

3. Domain name + port

window.location.host

结果:www.myurl.com:8866

4. Domain name

window.location.hostname()

结果:www.myurl.com

5. Port

window.location.port()

结果:8866

6. Path part

window.location.pathname()
结果:/test

7. Request parameters

window.location.search

结果:?id=123&username=xxx

Method 2: use

onLoad(options) {
			//  获取url路由参数
			var launchOptions = uni.getLaunchOptionsSync()
			console.log("goodsDetail onLoad launchOptions", launchOptions.query)
			// 存储分享者微信openID
			uni.setStorageSync("sharerInfo", launchOptions.query)
			
		},

 

Guess you like

Origin blog.csdn.net/u013302168/article/details/131123577