文件下载使用 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
                        }
                 }
               }
posted @ 2022-07-04 16:36  泽泽生龙  阅读(579)  评论(0)    收藏  举报