post / get 請求方式下載文件

export function downFile(url,parameter,method){
  return axios({
    url: url,
    params: parameter,
    method:method ,
    responseType: 'blob'
  })
}

downFile(this.url.exportXlsUrl,param,'get').then((data)=>{
        if (!data) {
          this.$message.warning("文件下載失敗")
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data]), fileName+'.xls')
        }else{
          let url = window.URL.createObjectURL(new Blob([data]))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName+'.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link); //下載完成移除元素
          window.URL.revokeObjectURL(url); //釋放掉blob對象
        }
      })
相關文章
相關標籤/搜索