跳转页面时候使用 使用JavaScript encodeURIComponent() 函数转码字符串作为 URI 组件进行编码
setPageInfo(item){
location.href = 'newPage.html?data=' + encodeURIComponent(JSON.stringify(item))
}
页面使用方法 然后调用 decodeURIComponent 解码即可
getItem(name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
console.log(window.location.search.substr(1));
let r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
}
return null;
}
let q = JSON.parse(this.getItem('data'));
-----------------方法二------------------
js的escape()和unescape() 函数 来进行加密和解密
提示:ECMAScript v3 已从标准中删除了 unescape() 函数,并反对使用它,因此应该用 decodeURI() 和 decodeURIComponent() 取而代之。
评论