This. $ refs [ "dataFormRef"]. resetFields ()는 el-form 형식에서 적용되지 않습니다.

추가, 삭제, 수정, 확인시 팝업창은 양식입니다. 폼 추가시 폼이 리셋되지 않았고, 그 값이 초기 값으로 리셋되지 않고 검증 결과가 제거 된 것을 발견했습니다.

먼저 양식 작성 방법을 살펴보십시오.

-----------------------------------错误示例------------------------------------------
<el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      v-loading="dataFormLoading"
      @keyup.enter.native="dataFormSubmitHandle()"
      label-width="80px"
    >
       <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item prop="planId" label="名称">
            <el-select
              v-model="dataForm.planId"
              filterable
              style="width: 100%"
              @change="handlePlant"
            >
              <el-option
                v-for="item in planList"
                :key="item.plantid"
                :label="item.planname"
                :value="item.planid"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
</el-form>

--------------------------------下面为正确示例-----------------------------

<el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataFormRef"
      v-loading="dataFormLoading"
      @keyup.enter.native="dataFormSubmitHandle()"
      label-width="80px"
    >
       <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item prop="planId" label="名称">
            <el-select
              v-model="dataForm.planId"
              filterable
              style="width: 100%"
              @change="handlePlant"
            >
              <el-option
                v-for="item in planList"
                :key="item.plantid"
                :label="item.planname"
                :value="item.planid"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
</el-form>

그런 다음 resetFields ()가 사용되는 위치를 살펴보십시오.

init() {
      this.visible = true;
      this.getPlantList();
      this.$nextTick(() => {
        // this.$refs["dataForm"].resetFields();//之前写法,ref定义的不要和绑定的数组名字重复
        this.$refs["dataFormRef"].resetFields();//绑定ref名字
        this.dataForm.plantId = this.storePlantId;
        if (this.storePlantId) {
          this.getInfo();
        }
      });
},

 

 

추천

출처blog.csdn.net/XU441520/article/details/113262873