Vue遇到的问题

1.下载文件时window.location.href=url只能使用get请求,get请求时如果参数过长,浏览器会报400错误,这时需要使用post请求。可以用模拟提交表单的方式实现下载文件:

      exportOk(){
         let demoUrl = gl.serverURL + "/common/tool/export";
         let temp_form = document.createElement("form");
         // 设置form属性
        temp_form.action = demoUrl;
        temp_form.target = "_self";
        temp_form.method = "post";
        temp_form.style.display = "none";
        //使用input参数会截断,应该是input对字符有长度限制
        let opt = document.createElement("textarea");
        opt.name = "sql";
        opt.value = sql;
        temp_form .appendChild(opt);
        document.body.appendChild(temp_form);
        // 提交表单
        temp_form .submit();
      }
posted @ 2019-05-06 18:10  叶落撒  阅读(141)  评论(0编辑  收藏  举报