axios 多种提交方式

application/x-www-form-urlencoded
const { sourceName, tableName } = this.selectKeys;
            var params = new URLSearchParams();
            params.append("columnName", value.columnName);
            params.append("tableName", tableName);
            params.append("sourceName", sourceName);
            axios
              .post(
                globalConfig.baseURLC + `dbconns/deleteTableStructure`,
                params,
                {
                  headers: {
                    "content-type": "application/x-www-form-urlencoded",
                  },
                }
              )
              .then((res) => {
                if (res.data.code == "200") {
                  this.$message({
                    type: "success",
                    message: "删除成功!",
                  });
                } else {
                  this.$message({
                    type: "info",
                    message: "删除失败!",
                  });
                }
                this.reloadTable();
              });
multipart/form-data
const { sourceName, tableName } = this.selectKeys;
            let formData = new FormData();
            formData.append( "file", new Blob([reader.result]), this.importFileConfig.fileList[0].name);
            formData.append( "sourceName", sourceName);
            formData.append( "tableName", tableName);
            axios.post(
              globalConfig.baseURLC + `dbconns/structureImport`,
              formData,
              {
                headers: {
                  "Content-Type": "multipart/form-data",
                },
              }
            ).then((res) => {
              loading && loading.close();
              clearTimeout(timer1);
              if (res.data.code == "200") {
                this.reloadTable();
                this.$message({
                  type: "success",
                  message: "导入成功!",
                });
              } else {
                this.$message({
                  type: "info",
                  message: "导入失败!"+res.data.msg,
                });
              }
              
              this.importFileConfig.visible = false;
              this.importFileConfig.fileList = [];
            });

常规

axios
            .post(
              globalConfig.baseURLC +
                `dbconns/addTableColumn/${sourceName}/${tableName}`,
              this.dialogConfig.form
            )
            .then((res) => {
              this.dialogConfig.visible = false;
              this.reloadTable();
              this.$message({
                message: "新增成功!",
                type: "success",
              });
            });

 

posted @ 2022-11-16 13:55  木章  阅读(157)  评论(0)    收藏  举报