• 文件下载使用 http 请求


       //http请求  
                      let Http =new XMLHttpRequest();
                      let url =  process.env.VUE_APP_BASE_API + '/tb-nationwide/downloadEvaluationTaskRecord?fileName=' +  this.form.getFieldValue('fileName')+'&xy='+this.downParam.xy;
                      Http.open('GET', url, true); // 用于初始化一个请求,method,url,async
                      Http.send(); // 用于发送请求,调用后请求才会真的发出
                      Http.onreadystatechange = (e) => {
                        if(Http.readyState === 4 &&Http.status === 200) {
                          console.log("eeeeeeeeee", Http)

                        //   if (JSON.parse(Http.response)) {
                        //      let res=JSON.parse(Http.response)
                        //     this.$message.info(res.message)
                        //   } else {
                        //       window.location.href = process.env.VUE_APP_BASE_API + '/tb-nationwide/downloadEvaluationTaskRecord?fileName=' +  this.form.getFieldValue('fileName')+'&xy='+this.downParam.xy
                        // }
                           if (typeof Http.response == 'string') {

                                try {
                                   let res=JSON.parse(Http.response)
                                   this.$message.info(res.message)
                                } catch(e) {
                                  window.location.href = process.env.VUE_APP_BASE_API + '/tb-nationwide/downloadEvaluationTaskRecord?fileName=' +  this.form.getFieldValue('fileName')+'&xy='+this.downParam.xy
                                }

                           } else {
                                window.location.href = process.env.VUE_APP_BASE_API + '/tb-nationwide/downloadEvaluationTaskRecord?fileName=' +  this.form.getFieldValue('fileName')+'&xy='+this.downParam.xy
                            }
                     }
                   }
  • 相关阅读:
    编写可维护的JavaScript代码(部分)
    Canvas
    初识ES6
    vue.js入门上
    ASP.NET中的物理路径与虚拟路径
    慎用标签选择器
    PHP服务器负载判断
    mac下安装redis
    mac安装memcache
    MySQL定时检查是否宕机并邮件通知
  • 原文地址:https://www.cnblogs.com/chenlongsheng/p/16443445.html
Copyright © 2020-2023  润新知