需求:在开发过程中我们会遇到通过链接的方式下载,下载的文件有时候会出现报错
“This XML file does not appear to have any style information associated with it. The document tree is shown below.”
这个问题是被bucket-referer策略拒绝,服务给拒绝访问的。
解决方案:
我们可以通过给a标签设置no-referrer
function downloadFile () {
const link = document.createElement('a');
// 需要下载的链接地址(state.batchimportCenterfileDownload)
link.href=state.batchimportCenterfileDownload
link.setAttribute('referrerpolicy','no-referrer');
link.click()
}