微信小程序生成二维码之传参(接收的参数乱码该咋解决)

先说我的案例,我需要的是,扫码进入不同的区域展示(因此这个就需要进行二维码路径传参),大致思路:接收数据,然后根据所接收的数据进行判断,展示不同的区域。

我是用的草料二维码生成的 - https://cli.im/weapp

路径是这样的:pages/addPage/addPage?location=阿里爸爸

在我通过生成的二维码进入的时候发现,我得到的参数,是被微信小程序转译后的(\u963f\u91cc\u7238\u7238)不是我所需要的内容。转译地址:http://www.jsons.cn/unicode/

因此,我们就需要转译,通过所接收的参数进行转译然后得到正确的字符(阿里爸爸)

下串代码只做接收并进行转译操作

onLoad(option){
	this.currentLocation = option.location;
	//默认如果没有传输地址就为嘻嘻
	if (!this.currentLocation || this.currentLocation === undefined || this.currentLocation.trim() === '') {
		this.currentLocation = '嘻嘻';
	} else if (this.currentLocation.indexOf('\\u') != -1) {
		// UNICODE转中文
		this.currentLocation = unescape(this.currentLocation.replace(/\\u/g, '%u'));
	} else if (this.currentLocation.indexOf('%') != -1) {
		// encodeURI 转中文
		this.currentLocation = decodeURI(this.currentLocation);
	}
}

以上代码希望能帮助到您,有什么需要帮助的欢迎留言板留言哦!一起加油吧!

猜你喜欢

转载自blog.csdn.net/qq_42899245/article/details/107787025
今日推荐