我正在用Typescript创建一个表单,React将为API设置参数。使用正确的参数,API将为我下载文件。我想知道是否有一些简单的方法可以做到这一点?
尝试使用抓取功能,但是当我只想跳入API时不需要这么做吗?
const App = () => {
return (
<div style={{ textAlign: "center" }}>
<MyForm onSubmit={({ email, firstName, lastName }) => {
// I dont know what i should put here.
}}
/>
</div>
);
};
答案 0 :(得分:0)
如果有人遇到相同问题,这是提取文件的解决方案。
fetch(url + email)
.then(response => response.blob())
.then(blob => URL.createObjectURL(blob))
.then(url => {
window.open(url, '_blank');
URL.revokeObjectURL(url);
});
}