vue 下載文件前端代碼

exportFileHandle (name) {
  this.$http({
    url: this.$http.adornUrl('/preschool/export/zip'),
    method: 'get',
    responseType: 'blob',
    params: this.$http.adornParams({
      'fileName': name
    })
  }).then(({data}) => {
    let nowDate = new Date()
   //const blob = new Blob([data],{type: 'application/vnd.ms-excel'})
   //let filename = name + '.xls'
    const blob = new Blob([data],{type: 'application/zip'})
    let filename = '期末總結' + dateFilter(nowDate,1) + '.zip'
    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)
  })
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章