官网说明,
resetFields | 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 |
1.resetFields 是用于重置表单数据为初始化,不是进行清空处理
2.异常--新增
未在el-form标签指定 ref
未在el-form-item标签指定 prop
正确用法
<el-form :model="numberValidateForm" ref="numberValidateForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="年龄" prop="age" >
<el-input type="age" v-model.number="numberValidateForm.age" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('numberValidateForm')">提交</el-button>
<el-button @click="resetForm('numberValidateForm')">重置</el-button>
</el-form-item>
</el-form>
重置方法
this.$refs[formName].resetFields();
2.异常--编辑
编辑时,由于需要给表单初始数据,所以当再次调用重置时,数据为进入表单前的数据。
正确用法:
a.先打开表单
this.dialogVisible = true
b.回调函数延迟在下一次dom更新数据后调用
this.$nextTick(function(){
this.dataForm = Object.assign({}, params.row);
})
这样的话,在初始化的时候,表单数据不会被更改