下载文件
<div class="btns-default" style="width: 150px;margin-left: auto;" @click="download" > 下载 </div>
download () { Axios({ baseURL: Api.baseUrl, url: rfid_file_download, params: {}, responseType: 'blob', headers: { Accept: 'application/octet-stream', }, }).then(res => { let blob = new Blob([res.data], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }) // response就是接口返回的文件流,输出的文件类型不同,type也不同 let objectUrl = URL.createObjectURL(blob) let link = document.createElement("a") // 创建a标签 link.href = objectUrl link.download = "网络测试方案" // 自定义文件名 link.click() // 下载文件 URL.revokeObjectURL(objectUrl) // 释放内存 }).catch(error => { this.$message.error(error) }) },
type类型大全
| 输出文件类型 | type |
| .avi | video/x-msvideo |
| .bin | application/octet-stream |
| .doc | application/msword |
| .docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| .eot | application/vnd.ms-fontobject |
| .gif | image/gif |
| .htm .html |
text/html |
| .jar | application/java-archive |
.jpeg.jpg |
image/jpeg |
| .js | text/javascript |
| .json | application/json |
| .png | image/png |
| application/pdf | |
| .ppt | application/vnd.ms-powerpoint |
| .pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
| .rar | application/x-rar-compressed |
| .svg | image/svg+xml |
| .tar | application/x-tar |
| .txt | text/plain |
| .webp | image/webp |
| .woff | font/woff |
| .woff2 | font/woff2 |
| .xhtml | application/xhtml+xml |
| .xls | application/vnd.ms-excel |
| .xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
| .zip | application/zip |
| .7z | application/x-7z-compressed |

浙公网安备 33010602011771号