0👍
The Element UI form seems to latch onto the data it gets initialized with, and resetFields()
reinitializes the form with that data. You could defer the watcher until the next tick so that the component’s initially empty empInfo
could be propagated to the Element UI form as initial data, which would then be used in resetFields()
.
watch: {
empData: {
immediate: true,
handler(value) {
this.$nextTick(() => {
if (value) {
this.empInfo = value;
}
});
}
}
}
0👍
If you use Parent and Child component, it is good practise to emit data as output to parent component and then process data. This parent child pattern is good for making dynamic form. Reset method cleares your form.
getUserData() {
if (this.$refs.empInfo.validate()) {
this.$emit('get-user-data', this.empInfo);
this.$refs.empInfo.reset();
}
}
- [Vuejs]-VueJS disable sorting when user enters data
- [Vuejs]-Sort Array by Child Computed Property in Vue
Source:stackexchange.com