How does vue + ElementUI close the dialog box emptying verification after the addition?

clipboard.png
, , , , ,

clipboard.png
html

        <div class="section_add">
          <el-dialog title="" :visible.sync="addUser" width="60%" :before-close="closeDialog">
            <div class="decorate">
              <i class="close" @click="addUserOff("ruleForm")"></i>
              <i class="bag"></i>
            </div>
            <div class="add_content clearfix">
              <el-form ref="ruleForm" :rules="rules" :model="ruleForm" label-width="165px">
                <el-col class="add_content_one">
                  <el-form-item label="" prop="departCode">
                    <el-input v-model="ruleForm.departCode" placeholder=""></el-input>
              </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addUserOff("ruleForm")"> </el-button>
                <el-button type="success" @click="submitForm("ruleForm")"> </el-button>
              </span>
          </el-dialog>
        </div>

js

      // 
      submitForm(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.addUserData();
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
      // 
      addUserData(formName) {
        this.addSuperiorDepartment();
        this.$ajax
          .post(this.$api.departmentData, this.ruleForm)
          .then(res => {
            if (res.data.status == 200) {
              this.$message({
                type: "success",
                message: "!"
              });
              this.ruleForm = {};
              this.addUser = false;
              this.$refs[formName].resetFields();
              this.ztreeData();
            }
          })
          .catch(err => {
            console.log("addUserData", err);
          });
      },
       // 
      addUserOff(formName) {
        this.addUser = false;
        this.$refs[formName].resetFields();
      },
Mar.16,2021

ref= "dialogForm" @ close= "closeDialog"
on el-form, and then this.$refs.dialogForm.resetFields ()

in the closeDialog method.

demo


same question: https://codeshelper.com/q/10.

Menu