我想按REST调用下载Excel。如果我使用Postman测试端点,它工作正常。但是,如果我在我的网站上启动请求,则响应是可以的,但我不知道如何更改对Excelfile下载的响应。
这是我的代码:
async export () {
const data = await generateExport()
const blob = new Blob([data], {
type:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
})
require('downloadjs')(
blob,
'FileName_' +
new Date().toLocaleDateString() +
'.xlsx',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
}
OR
async export () {
var data = await generateExport()
require('downloadjs')(
data,
'FileName_' +
new Date().toLocaleDateString() +
'.xlsx',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
}
感谢您的回答 祝福
答案 0 :(得分:1)
现在我将downloadjs用作ES6。一段时间后,我看到服务器响应不仅是文件。它在一个也称为数据的容器中。现在,我只是在对象中导航到源。
import * as download from 'downloadjs'
...
var data = await generateExport();
download(
data.data,
'NameOfTheFile_' + new Date().toLocaleDateString() + '.xlsx',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'
)