我的接收数据进行处理的代码为:
download_signal_list() {return new Promise((resolve, reject) => {get_download_signal({project_id: this.projectId,version_id: this.versionId}).then(response => {const url = window.URL.createObjectURL(new Blob([response.data]))const link = document.createElement('a')link.href = urlconst timestamp = this.gettimestamp(new Date().getTime() / 1000)const filename = timestamp + '-信号对接表.xlsx'link.setAttribute('download', filename)document.body.appendChild(link)link.click()}).catch(error => {reject(error)})})},
确实可以下载下来,但是打开后为乱码。
解决办法:
后端传的是blob类型文件,所以前端接收时也要限制一下类型,
接收的请求代码配置为:
export function get_download_signal(data) {return request({url: baseURL + 'mf_project/signal_docking/download_signals',method: 'get',params: data,responseType: 'blob' // 一定一定要加上})
}
之后再下载就可以正确显示啦