I have a parent component and I am assigning values in child component form. But after submitting the form I want form field should be empty.
I am using resetFields function for resetting value but when I am using these function it is setting last value, what I send it from parent component instead of reset value I want form fields should be empty.
<script>
export default {
props: ["empData"],
data {
return() {
empInfo: {
name: "",
id: null,
age: null
}
}
},
methods: {
getUserData() {
if (response.status == "SUCCESS") {
this.$refs['empInfo'].resetFields();
}
}
}
watch: {
empData: immediate: true,
handler() {
this.empInfo = this.empData;
}
}
}
</script>
<template>
<div>
<el-form :label-position="labelPosition" :model="empInfo" status-icon :rules="rules" ref="empInfo">
<el-form-item label="Employee Name" prop="name">
<el-input v-model="empInfo.markupName"></el-input>
</el-form-item>
<el-form-item label="EMployee Id" prop="id">
<el-input v-model="empInfo.id"></el-input>
</el-form-item>
<el-form-item label="Employee Age" prop="age">
<el-input v-model="empInfo.age"></el-input>
</el-form-item>
<el-button @click="getUserData">Submit</el-button>
</div>
</template>
created()
and then recall this method on reset or after the data changes. – ssc-hrep3