美文网首页
fetch请求接口下载文件

fetch请求接口下载文件

作者: 吖_7c06 | 来源:发表于2022-05-17 15:54 被阅读0次
    fetch(`url`, {
                method: 'POST',
                  body: JSON.stringify({
                    id: this.id
                  }),
                  headers: new Headers({
                      'Authorization': "localStorage.getItem("access_token"),
                      'Content-Type': 'application/json'
                  }),
              })
             .then(res => res.blob())
             .then(data => {
                  const blobUrl = window.URL.createObjectURL(data);
                  const a = document.createElement('a');
                  a.download = regFileNames+'.txt';
                  a.href = blobUrl;
                  a.click();
    });
    

    相关文章

      网友评论

          本文标题:fetch请求接口下载文件

          本文链接:https://www.haomeiwen.com/subject/fujnurtx.html