(vue.js) element ui form reset this.$ refs [formName] .invalid Fields () does not execute

I have a form form in a pop-up box to add content to the page. Click the cancel button to empty the contents of the form itself. Using this.$refs ["addServiceForm"] .invalid Fields () does not work. Console comes out
console.log (this.$refs ["addServiceForm"]. ResetFields ()); is actually undefined.

<el-dialog
          title=""
          :visible.sync="addServiceDialogVisible"
          width="400px">
          <div>
            <el-form ref="addServiceForm">
              <table class="base_table">
                <tbody class="table_body1">
                  <tr>
                    <td width="15%" class="text_align_right"></td>
                    <td>
                      <el-input v-model="serviceName"></el-input>
                    </td>
                  </tr>
                  <tr>
                    <td class="text_align_right"></td>
                    <td>
                      <el-input v-model="serviceShorterName"></el-input>
                    </td>
                  </tr>
                  <tr>
                    <td class="text_align_right"></td>
                    <td>
                      <el-select v-model="serviceType" placeholder="" @change="selectChange" style="width:100%">
                        <el-option
                          v-for="item in serviceTypeOptions1"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select>
                    </td>
                  </tr>
                  <tr>
                    <td class="text_align_right"></td>
                    <td>
                        <el-input type="textarea" :rows="2" v-model="serviceRemarks"></el-input>
                        <!--resize="none"-->
                    </td>
                  </tr>
                </tbody>
              </table>
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer modalCenter">
            <el-button type="primary" @click="addNewService"> </el-button>
            <el-button @click="cancleAddService"> </el-button>
          </span>
        </el-dialog>
cancleAddService(){
      this.resetForm("addServiceForm");
      // this.serviceName="";
      // this.serviceShorterName="";
      // this.serviceRemarks="";
      // this.serviceType="";
      this.addServiceDialogVisible=false;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      console.log("form:"+this.$refs["addServiceForm"].resetFields());
    }
Mar.06,2021

el-form needs to receive a model , and needs to be used in conjunction with el-form-item , and binds the prop attribute on el-form-item to make the resetField method work.

<el-form :model="addServiceData" ref="addServiceForm">
    <el-form-item label="" prop="mobile">
       <el-input v-model="data.mobile" placeholder=""></el-input>
     </el-form-item>
</el-form>

and addServiceData should be an object, defined in data, like this

data(){
    return {
        addServiceData: {
            mobile: ''
        }
    }
}

external reset uses

in this way
 
  1. use this.$refs instead of this.$ref
  2. with this.$nextTick (() = > {})
  3. model / ref in el-form and prop in el-form-item check it again
< hr >

10:55:49 on June 30, 2020

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36f77-2c03a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36f77-2c03a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?