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

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

我是用的草料二维码生成的 - 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);
	}
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值