前端blob格式导出数据

downloadBinaryCsv(data, fileName) {
  const url = window.URL.createObjectURL(new Blob([data],{type:content-type}))
  const link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', fileName+‘csv’)
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
}

需要导出excel、csv、word、zip压缩文件之类的,在导出excel和word中需要知道对应的content-type属性,一下是type列表
后缀 MIME Type
.doc application/msword
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.xls application/vnd.ms-excel
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.ppt application/vnd.ms-powerpoint
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation

你可能感兴趣的:(VUE基础学习)