欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue下載excel的實(shí)現(xiàn)代碼后臺(tái)用post方法

 更新時(shí)間:2019年05月10日 16:51:44   作者:六一兒童節(jié)  
這篇文章主要介紹了vue下載excel的實(shí)現(xiàn)代碼,后臺(tái)用post方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下

后臺(tái)方法的參數(shù)必須是@RequestBody修飾的。

      前臺(tái)關(guān)鍵代碼:   

axios ( {
     method : 'post',
     url : api.exportPlayTime , // 請(qǐng)求地址
     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 對(duì)象
       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()
   },

總結(jié)

以上所述是小編給大家介紹的vue下載excel的實(shí)現(xiàn)代碼后臺(tái)用post方法,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

最新評(píng)論