const download = async () => { try { axios.post('http://127.0.0.1:5000/download', {'id':data.value}, { responseType: 'blob' }) .then(response => { //通过头传递参数 console.log('Custom Message:', response.headers.get('h')); const h = response.headers.get('h') // 创建一个 URL 对象 const imageUrl = URL.createObjectURL(new Blob([response.data])); // 创建一个 <a> 标签并设置下载属性 const link = document.createElement('a'); link.href = imageUrl; link.download = `${h}.docx`; // 下载文件的名称 // 模拟点击下载 link.click(); // 释放 URL 对象 URL.revokeObjectURL(imageUrl); }) .catch(() => { const open3 = () => { ElMessage({ message: '后台无数据', type: 'warning', }) } open3() }); } catch (error) { // 捕获异常,显示错误消息 new proxy.$tips('服务器发生错误', 'error').mess_age(); } };
|