zoukankan      html  css  js  c++  java
  • vue 文件流下载xlsx 功能实现

    downLoadFile (url, name) {
                    this.xhr = new XMLHttpRequest()
                    this.xhr.open('GET', url, true)
                    this.xhr.responseType = 'blob'
                    var vmThis = this
                    this.xhr.onload = () => {
                        if (this.xhr.status === 200) {
                            if (this.xhr.response && this.xhr.response.size && this.xhr.response.size > 0) {
                                let file = this.xhr.response
                                let fileName = name
                                if ('msSaveOrOpenBlob' in navigator) {
                                    window.navigator.msSaveOrOpenBlob(file, fileName)
                                } else {
                                    let fileUrl = window.URL.createObjectURL(file)
                                    let a = document.createElement('a')
                                    a.download = fileName
                                    a.href = fileUrl
                                    document.getElementsByTagName('body')[0].appendChild(a)
                                    a.click()
                                    a.parentNode.removeChild(a)
                                    window.URL.revokeObjectURL(fileUrl)
                                }
                            }
                        } else {
                            //
                        }
                    }
                    this.xhr.setRequestHeader('x-manage-token', this.$store.state.userInfo.data.sessionId)
                    this.xhr.send()
                },

    this.downLoadFile(this.url+'/authc/jzmOrder/exportJzmOrder','')
     

    url 是后端接口全路劲    name 导出文件名称

  • 相关阅读:
    类与类之间的关系图
    UML介绍
    数据建模
    状态图
    部署图
    用例图
    业务建模
    时序图
    postgresql 维护手册
    ashx文件的使用(转)
  • 原文地址:https://www.cnblogs.com/taochengyong/p/10873480.html
Copyright © 2011-2022 走看看