我正在尝试返回一个具有两个属性的对象...正在生成blob并且需要时间来解决的问题。然而,在promise解析之前,javascript似乎会跳转到下一个函数(或“链中的链接”)。有没有办法让它在跳转到下一个函数之前等待这个嵌套属性解析?
fetch(prefix + '/download', {
method: 'POST',
.....
})
.then((response) => {
var contentDisposition = response.headers.get('content-disposition');
var fileName = contentDisposition.split('filename=')[1].split(';')[0];
return { blob: response.blob(), filename: fileName }
})
.then((blob) => {
return { href: URL.createObjectURL(blob.blob), filename: blob.filename }
})我收到Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.,大概是因为blob.blob返回了一个Promise,但还没有值。
发布于 2020-09-01 10:40:50
尝试使用自己的then()返回response.blob() promise,以返回最终数据
fetch(prefix + '/download', {
method: 'POST',
.....
})
.then((response) => {
var contentDisposition = response.headers.get('content-disposition');
var filename = contentDisposition.split('filename=')[1].split(';')[0];
return response.blob().then(blob =>{
return { href: URL.createObjectURL(blob), filename}
});
});https://stackoverflow.com/questions/63680476
复制相似问题