在这里插入图片描述
1,使用element-ui里面的el-upload组件进行文件上传,设置auto-upload为false不自动上传。后面我们通过设置请求头部通过表单的形式进行传参。

let config = {
   headers: {
     "Content-Type": "multipart/form-data"
   }
 };

2,防止跨域我们这里需要设置

  const instance = axios.create({
    withCredentials: true
  });

3,最终的代码请求方式如下

             headers: {
                "Content-Type": "multipart/form-data"
             }            
            const instance = axios.create({
              withCredentials: true
             });           
            var formData = new FormData();
            formData.append("data", {name:"jjj"});
            formData.append("sign", {age:29});
            formData.append("apkFile", '具体上传的文件地址');

            let config = {
              headers: {
                "Content-Type": "multipart/form-data"
              }
            };
            console.log(formData, config, "kklooo----");
            // return false
            self.$message({
              type: "success",
              message: "新增版本成功"
            });
            instance
              .post(
                "https://xxxxxxxx",
                formData,
                config
              )

              .then(response => {
                self.isdisabledFn = false;
                if (response.data.code == 200) {
                  self.$message({
                    type: "success",
                    message: response.data.msg
                  });
                } else {
                  self.$message({
                    type: "warning",
                    message: response.data.msg
                  });
                }
              });
Logo

前往低代码交流专区

更多推荐