daily-share icon indicating copy to clipboard operation
daily-share copied to clipboard

关于向服务端发送文件下载的一些细节,如exelce 文件下载了(2022-3-22)

Open yaogengzhu opened this issue 2 years ago • 1 comments

服务请求示例

Axios({
  method: 'post',
  url: sendURL,
  responseType: 'blob', // 这个位置需要加上
})
.then((response) => {
    const { status } = response;
    if (status === 200) {
        message.success('导出成功!');
        const url1 = window.URL.createObjectURL(new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' }));
        const link = document.createElement('a');
        link.href = url1;
        link.setAttribute('download', filename);
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    } else {
        message.error('导出失败');
    }
});

yaogengzhu avatar Mar 22 '22 09:03 yaogengzhu

XMLHttpRequest 属性 responseType 是一个枚举字符串值,用于指定响应中包含的数据类型。

URL.createObjectURL()

yaogengzhu avatar Mar 22 '22 09:03 yaogengzhu