Vue download file stream

  1. List item

Because the function requires the use of file streams for downloading or exporting, the following code is for reference only.

xls format configuration:

type: ‘application/vnd.ms-excel;charset=utf-8’,

xlsx format arrangement: type:'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet;charset=utf-8'

<el-button type="primary" plain  @click="allDownload">下载</el-button>
methods:{
    
    
allDownload() {
    
    
      const params = this.exportAllParams
      console.log(params)
      // const params = JSON.parse(JSON.stringify(this.searchParams))
      delete params.current
      delete params.size
      delete params.total
      allExportList(params).then((res) => {
    
    
        const blob = new Blob([res], {
    
    
          type: 'application/vnd.ms-excel'
        })
        const a = document.createElement('a')
        const href = window.URL.createObjectURL(blob)
        a.href = href
        a.download = '实时监控'
        document.body.appendChild(a)
        a.click()
        // console.log(a)
        document.body.removeChild(a)
        window.URL.revokeObjectURL(href)
      })
    },
}

Guess you like

Origin blog.csdn.net/outaidered/article/details/129306244