zoukankan      html  css  js  c++  java
  • (办公)vue下载excel,后台用post方法

      后台方法的参数必须是@RequestBody修饰的。

          前台关键代码:

         

    axios ( {
              method : 'post',
              url : api.exportPlayTime , // 请求地址
              data : {
                choose : type,
                begindate : startDate,
                enddate : endDate
              },
              responseType : 'arraybuffer',
              observe: 'response',
            } )
              .then ( ( res ) => {
    
                const fileName = ""+filename+".xlsx"
                let blob = new Blob([res.data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
                if ( 'download' in document.createElement ( 'a' ) ) { // 非IE下载
                  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 )
                } else { // IE10+下载
                  navigator.msSaveBlob ( blob, fileName )
                }
    
              })
    download(data) {
            if (!data) {
              return
            }
            let url = window.URL.createObjectURL(new Blob([data]))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', 'excel.xlsx')
    
            document.body.appendChild(link)
            link.click()
          },
  • 相关阅读:
    [某鸥实训记][objective-c][第四天][个人笔记]
    [某鸥实训记][objective-c][第三天][作业]打地鼠X2
    [某鸥实训记][objective-c][第三天][个人笔记]
    京东书籍爬取
    抽屉爬取
    scrapy项目renrencookie
    scrapy项目suningbook
    scrapy项目4
    scrapy项目3
    scrapy项目2
  • 原文地址:https://www.cnblogs.com/historylyt/p/10845090.html
Copyright © 2011-2022 走看看