前后端交互post方法下载后端返回的文件流

let obj = JSON.stringify(payload);

console.log(obj);

fetch('/dview8/api/report/export', {

method: 'POST',

headers: {

'Content-Type': 'application/json',

},

body: obj,

responseType:'blob'

})

.then(res => res.blob())

.then(data => {

console.log(data);

let blobUrl = window.URL.createObjectURL(data);

const a = document.createElement('a');

a.style.display = 'none';

a.download = this.state.fileName;

a.href = blobUrl;

a.click();

a.remove();

});

}

你可能感兴趣的:(vue,java)