当前位置: 移动技术网 > IT编程>开发语言>JavaScript > (办公)vue下载excel,后台用post方法

(办公)vue下载excel,后台用post方法

2019年05月11日  | 移动技术网IT编程  | 我要评论

1000人艺体艺术波谷,济宁郑媛媛照片全集,贝爷中国节目

  后台方法的参数必须是@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()
      },

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网