encodeURIComponent和decodeURIComponent(推荐使用)
它用于对URL的组成部分进行个别编码,而不用于对整个URL进行编码。
因此,"; / ? : @ & = + $ , #",这些在encodeURI()中不被编码的符号,在encodeURIComponent()中统统会被编码

let url = 'aaa?userId=0VqMhXM2fqy10ZchzbKiJw%3D%3D&nickName=张三';
let arr = url.split('?')[1].split('&');
for (let i = 0; i < arr.length; i++) {
let key = arr[i].split('=')[0];
let value = arr[i].split('=')[1];
if (key == 'userId') {
this.userId = decodeURIComponent(value);
} else if (key == 'nickName') {
this.nickName = value;
}
}
console.log('this.userId', this.userId);
打印结果

网友评论