uniapp页面传参带有特殊符号,使用encodeURIComponent转义

您所在的位置:网站首页 url中大括号 uniapp页面传参带有特殊符号,使用encodeURIComponent转义

uniapp页面传参带有特殊符号,使用encodeURIComponent转义

2023-08-17 17:12| 来源: 网络整理| 查看: 265

 encodeURIComponent进行编码

let str = 'kohePOtjXz3AVIo=='; uni.navigateTo({ url: `../list/list?antiFakeCode=${encodeURIComponent(this.antiFakeCode)}` })

解码时用decodeURIComponent进行解码

onLoad(options) { console.log('options', options) this.antiFakeCode = decodeURIComponent(options.antiFakeCode); },

如果传的时对象,比如:

let obj = {a:1,b:2};

需要先把对象转为字符串

let data = JSON.stringify(obj);

转换完成后在用encodeURIComponent进行编码

uni.navigateTo({ url: `../list/list?antiFakeCode=${encodeURIComponent(this.data)}` })

跳转页面后再用decodeURIComponent解码,再用JSON.parse()转为对象

onLoad(options) { console.log('options', options) let data= decodeURIComponent(options.data); let datas = JSON.parse(data); },

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3