都是对URL进行编码,区别是编码的范围不同;
encodeURI 范围小,不编码:“ACII字母、数字、~!@#$&()=:/,;?+* ”
encodeURIComponent范围大,不编码:“ASCII字母、数字、~!*()”
举例:
const url=http://www.cnblogs.com/season-huang/some other thing
encodeURI(url);
//http://www.cnblogs.com/season-huang/some%20other%20thing
encodeURIComponent(url)
//http%3A%2F%2Fwww.cnblogs.com%2Fseason-huang%2Fsome%20other%20thing