The reason why the form reset in element-ui does not take effect, and the solution

The resetFields method is to reset the form to its initial value , that is, to reset the data in the form to the value when the dom node is rendered, rather than to an empty object.

In other words, when your form data is assigned before the dom node is rendered, its initial value will not be empty.

Also, objects in Vue cannot be directly assigned to another object

Solution: To assign value to the form object, you should use the $nextTick method after the dom node rendering is completed, and to

The assigned data is escaped

$nextTick: Change vuedom node update to sync

//this.form:是表单对象
//data:是值
 this.$nextTick(()=>{
     this.form = JSON.perse(JSON.stringify(data))
  })

Precautions for using resetFields: set the prop attribute, the attribute value should be the same as the model value, if this attribute is not set,

resetFields is not effective

Guess you like

Origin blog.csdn.net/weixin_65565362/article/details/125533936