encodeurl 和 encodeurlComponent都是 Js对 url 编码的函数
区别:
encodeurl 着眼于对整个 url 进行编码,
特殊含义的符号,例如右方这些 ;/ ? : @ & = + $ , # 是不进行编码的。
encodeurlComponent 对于 url 的组成进行个别编码,
所以,以上举例的一些符号,是可以进行编码的。
测试代码:
<html>
<body>
<script type="text/javascript">
document.write(encodeURI("http://www.w3school.com.cn")+ "<br />")
document.write(encodeURI("http://www.w3school.com.cn/My first/")+ "<br />")
document.write(encodeURI(",/?:@&=+$#")+ "<br />")
document.write(encodeURIComponent("http://www.w3school.com.cn")+ "<br />")
document.write(encodeURIComponent("http://www.w3school.com.cn/My first/")+ "<br />")
document.write(encodeURIComponent(",/?:@&=+$#")+ "<br />")
</script>
</body>
</html>
编译结果:
//使用encodeURI
http://www.w3school.com.cn
http://www.w3school.com.cn/My%20first/
,/?:@&=+$#
//使用encodeURIComponent
http%3A%2F%2Fwww.w3school.com.cn
http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F
%2C%2F%3F%3A%40%26%3D%2B%24%23
注释:所以一般情况下,http路径采用 encodeurl ( ) ,
而在路径中携带参数的一般使用 encodeurlComponent ( ) .
原文链接:原文转载链接
W3C school 的原文链接:
encodeurlComponent 函数传送门
encodeUrl 函数传送门
ps: 本人在搜索 vue有关授权问题时看到了这部分的东西,
具体已通知相关作者,上方是官方链接,以上 “编码函数” 均有与之对应的
“解码函数”,详见 W3C school.