The solution to the element-ui form reset resetFields method does not work

Problem description:
There are often cases where the same pop-up window needs to be reused for adding and editing; refresh the page, first click Edit to close the pop-up window and then click Add. At this time, the method of resetting the form when the pop-up window is closed has no effect. :

this.$refs.form.resetFields();

The role of resetFields:

1. Reset the entire form and reset the fields to the initial value
2. Remove the verification result

Problem analysis result:

1. The resetFields resets the initial value
2. The initial value of the form is called when the mounted life cycle is executed.
3. If the initial value is modified before the mounted life cycle is executed, the resetFields method will use the modified value as the initial value

Solution:
Put the echo data into setTimeout or nextTick

this.$nextTick(()=>{
    
    
	//这里赋值回显数据
})
//或者
setTimeout(()=>{
    
    
	//这里赋值回显数据
}.bind(this),0)

Note: If the above still does not solve the problem, it is recommended to check if the prop attribute is added to your el-form-item element.

Guess you like

Origin blog.csdn.net/weixin_43299180/article/details/115011248