描述:调用接口以后,后台返回的数据

 前端实现,下载功能。

前端打印res:

 那么接口必须加上这个

 页面下载:

 

    downloadFunc(data) {
      const date = new Date(+new Date() + 8 * 3600 * 1000)
        .toISOString()
        .replace(/T/g, ' ')
        .replace(/\.[\d]{3}Z/, '')
        .replace(/\-/g, '')
        .replace(/\:/g, '')
        .replace(/\s*/g, '')
      const fileName = 'ADEJJ' + date + '.xlsx'
      const blob = new Blob([data], { type: `'application/vnd.ms-excel';charset=utf-8` })
      const downloadElement = document.createElement('a')
      const href = window.URL.createObjectURL(blob)
      downloadElement.href = href
      downloadElement.download = fileName
      document.body.appendChild(downloadElement)
      downloadElement.click()
      document.body.removeChild(downloadElement)
      window.URL.revokeObjectURL(href)
    },

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐