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 导出文件名称

  • 相关阅读:
    图片上传
    中间件
    放大镜
    JQ编写楼层效果
    AJAX,PHP,前端简单交互制作输入框效果
    AJAX中使用post,get接收发送数据的区别
    PHP内写css样式
    计算2个日期相差的月份
    react-相关技术栈之-dva/dynamic
    es6相关知识点
  • 原文地址:https://www.cnblogs.com/taochengyong/p/10873480.html
Copyright © 2011-2022 走看看