パラメータ
url :リクエストパス
data: リクエストパラメータ
fileName: エクスポートされるファイル名
呼び出しメソッド
import { exportFilePost } from '../../../../utils/exportFile';
let url = 'xxxx/api';
let data = this.deriveData;
let name = 'ファイルをエクスポートする;
exportFilePost(url, data, name);
POST
export function exportFilePost(url, data, fileName) { fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8' }, body: JSON.stringify(data), }) .then((res) => { return res.blob(); }) .then((res) => { function downloadFileByBlob(blobUrl, filename) { const a = document.createElement('a'); a.download = filename; a.style.display = 'none'; a.href = blobUrl; document.body.appendChild(a); a.click(); document.body.removeChild(a); } const blobContent = new Blob([res], { type: 'application/octet-stream' }); const blobUrl = window.URL.createObjectURL(blobContent); let name = moment().locale('ja-JP').format('YYYY-MM-DD HH:mm:ss'); downloadFileByBlob(blobUrl, `${name}` + `${fileName}` + '.xlsx'); });}