async handleCheckFile (row) {
const fileUrl = row.fileUrl // 这个文件url 浏览器可以直接打开的 不是文件流也不是返回文件流的接口
const fileName = row.fileName; // 支持自定义的文件名
try {
const response = await axios.get(fileUrl, { responseType: 'blob' });
const contentType = response.headers['content-type'];
const blob = new Blob([response.data], { type: contentType });
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// 兼容IE浏览器
window.navigator.msSaveBlob(blob, fileName);
} else {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', fileName);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}
} catch (error) {
console.error('Error downloading file:', error);
}
// this.detailFun(row);
},
vue 根据文件url 下载文件
最新推荐文章于 2024-05-29 15:02:52 发布