我在我的服務器(NodeJS)上撰寫了一個代碼,它將使用 express res.download(path)將一個 .csv 檔案發送到前端。我想知道如何使用 fetch API 處理回應,這將允許前端下載發送的檔案(.csv)。
我在前端使用 reactJs。
uj5u.com熱心網友回復:
我能夠通過在我的前端使用downloadJs來解決這個問題
import download from 'downloadjs'
...
//get request
fetch(url).then(res => res.blob())
.then(blob => download(blob, 'name of file', 'data type')) // this line automatically starts a download operation
.catch(err => console.log(err));
我希望這可以幫助你
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/473608.html
標籤:javascript 节点.js 反应 表示 拿来
