post请求导出csv文件
场景:原本定义的请求是get请求的,但是因为请求参数过多,导致接口挂了,所以需要转成post请求
需要后端返回二进制格式
代码参上
// 导出数据 export function exportData(data) { return request({ url: ``, method: 'POST', data, baseURL: HOST, responseContentType: 'blob' }) } // 导出数据 handleDownload() { exportData(this.form).then(response => { const url = window.URL.createObjectURL(new Blob([response], {type:"text/csv;charset=utf8;"})) const link = document.createElement('a') link.style.display = 'none' link.href = url link.setAttribute('download', 'excel.csv') document.body.appendChild(link) link.click() document.body.removeChild(link) const timer = setTimeout(() => { this.$message({ message: '导出成功', type: 'success' }) clearTimeout(timer) }, 2000) }) }