在这里插入图片描述
其中encodeURI()主要用于整个URI(例如,http://www.jxbh.cn/illegal value.htm),而encodeURIComponent()主要用于对URI中的某一段(例如前面URI中的illegal value.htm)进行编码。它们的主要区别在于,encodeURI()不会对本身属于URI的特殊字符进行编码,例如冒号、正斜杠、问号和井字号;而encodeURIComponent()则会对它发现的任何非标准字符进行编码。
download(url) {
const link = document.createElement('a')
//对文件名进行转换编码,一些编码不能在url中传输,需要转换
let urlArr = url.split('/')
urlArr[urlArr.length - 1] = encodeURIComponent(urlArr.pop())
link.href = urlArr.join('/')
link.target = '_blank'
link.click()
}
参考:
https://blog.csdn.net/HXNLYW/article/details/84400724
https://www.w3school.com.cn/tags/html_ref_urlencode.asp