vue2 axios請求從後臺獲取文件流(自定義導出excel)

import axios from 'axios'
export default {
  post(url, param, title) {
    axios.post(url, param, { responseType: 'arraybuffer' })
      .then((res) => {
        if(res.status == "200") {
          const aLink = document.createElement("a");
          let blob = new Blob([res.data], {type: "application/vnd.ms-excel"})
          aLink.href = URL.createObjectURL(blob)
          aLink.download = title
          aLink.click()
          document.body.appendChild(aLink)
        }
      })
  }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章