The solution to the problem that elementUi form cannot be re-entered after resetFields

The solution to the problem that elementUi form cannot be re-entered after resetFields

1. Let's look at the document first

insert image description here
*Note that ' reset the entire form, reset all field values ​​​​to their initial values ​​and remove the verification results '

2. Code modification

html

<el-form label-width="100px" ref="addFormRef" :rules="rules" :model="addForm">
  <el-row>
    <el-form-item label="名称" prop="name">
      <el-input v-model="addForm.name" placeholder="请输入名称"></el-input>
    </el-form-item>
  </el-row>
  <el-row>
    <el-form-item label="数量" prop="num">
      <el-input v-model="addForm.num" placeholder="请输入数量"></el-input>
    </el-form-item>
  </el-row>
</el-form>

js

const addFormRef = ref(null);
addForm: {
    
    },
//清空
async set() {
    
    
  await nextTick();
  addFormRef.value.resetFields();
},

This can indeed clear the data, but the problem is that it cannot be entered after clearing

3. Solutions

js

const addFormRef = ref(null);
addForm: {
    
    
	name:'',
	num:''
}, //我们需要给他定义初始值 不能偷懒

Guess you like

Origin blog.csdn.net/weixin_44255044/article/details/128314222