封装的axios下载
// 下载数据 export const downloadFile = (id) => { return axios.request({ url: '/file-manage/file/download/' + id, method: 'get', responseType: 'blob' }) }
传入下载的文件名,对应的文件id来下载流格式的文件
// 下载文件 downloadFile (filename, id) { downloadFile(id).then(res => { console.log(res) if (!res) { return } let url = window.URL.createObjectURL(res.data) let link = document.createElement('a') link.style.display = 'none' link.href = url link.setAttribute('download', filename) document.body.appendChild(link) link.click() }).catch(err => { console.log(err.message) }) },