uni-app receives URL parameters

onLoad(options) {
			let params = this.getRequestParams();
			let mobile = params['mobile'];	// 参数名
			console.log(mobile )
		},
		methods: {
			// 获取utl参数
			getRequestParams() {
				let url = location.href;
				let requestParams = {};
				if (url.indexOf('?') !== -1) {
					let str = url.substr(url.indexOf('?') + 1); //截取?后面的内容作为字符串
					// console.log(str, '?后面的内容');
					let strs = str.split('&'); //将字符串内容以&分隔为一个数组
					// console.log(strs, '以&切割的数组');
					for (let i = 0; i < strs.length; i++) {
						requestParams[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
						// 将数组元素中'='左边的内容作为对象的属性名,'='右边的内容作为对象对应属性的属性值
					}
				}
				// console.log(requestParams, '处理后的对象');
				return requestParams;
			}
		}

If it is useful to you, pay attention to the blogger's applet, log in to give support, and any open source and useful source code will be uploaded to the applet in the future

 

Guess you like

Origin blog.csdn.net/qq_42543264/article/details/121491521