encodeURIComponent()主要用于对URI中的某一段进行编码。
encodeURIComponent()则会对它发现的任何非标准字符进行编码。
而decodeURIComponent() 能够解码使用 encodeURIComponent() 编码的所有字符串。
let uri="https://www.runoob.com/my test.php?name=ståle&car=saab";
let uri_encode=encodeURIComponent(uri); // 编码
console.log(uri_encode);
console.log(decodeURIComponent(uri_encode)); //解码
//一般使用 encodeURIComponent(JSON.stringify(url)) //进行编译 传递参数
//一般使用 JSON.parse(decodeURIComponent(url)) //正常解码 接收参数
//输出内容
1. https%3A%2F%2Fwww.runoob.com%2Fmy%20test.php%3Fname%3Dst%C3%A5le%26car%3Dsaab
2. https://www.runoob.com/my test.php?name=ståle&car=saab