上传&下载

作者: 猿分让我们相遇 | 来源:发表于2019-07-04 09:22 被阅读0次

用form-data形式上传需要在请求头定义

 headers: {
                'Content-Type': 'multipart/form-data'
            }

下载,如果是url形式使用a+download
如果是二进制形式需要
先设置请求头

{
  responseType:"blod"
}

接收后台数据时,需要使用new Blod

 downloadBtn(){
        requestServices.unitDownload()
          .then((res)=>{
            const content = res
            const blob = new Blob([content])
            const fileName = '班级模板.xlsx'
            if ('download' in document.createElement('a')) { // 非IE下载
              const elink = document.createElement('a')
              elink.download = fileName
              elink.style.display = 'none'
              elink.href = URL.createObjectURL(blob)
              document.body.appendChild(elink)
              elink.click()
              URL.revokeObjectURL(elink.href) // 释放URL 对象
              document.body.removeChild(elink)
            } else { // IE10+下载
              navigator.msSaveBlob(blob, fileName)
            }
          })
      },

相关文章

网友评论

    本文标题:上传&下载

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