antdv resetFields
时间: 2023-12-01 16:05:10 浏览: 62
The `resetFields` method is a function provided by the `Form` component in the Ant Design Vue library. It is used to reset the form fields to their initial values.
Here's an example:
```vue
<template>
<a-form :form="form">
<a-form-item label="Username" name="username">
<a-input v-model="form.username" />
</a-form-item>
<a-form-item label="Password" name="password">
<a-input.Password v-model="form.password" />
</a-form-item>
<a-form-item>
<a-button type="primary" @click="submitForm">Submit</a-button>
<a-button @click="resetForm">Reset</a-button>
</a-form-item>
</a-form>
</template>
<script>
export default {
data() {
return {
form: this.$form.createForm(this)
}
},
methods: {
submitForm() {
this.form.validateFields((err, values) => {
if (!err) {
console.log(values)
}
})
},
resetForm() {
this.form.resetFields()
}
}
}
</script>
```
In this example, we have a simple form with two input fields for username and password. When the user clicks the "Submit" button, we validate the form fields using the `validateFields` method provided by the `Form` component. If there are no errors, we log the form values to the console.
When the user clicks the "Reset" button, we call the `resetFields` method to reset the form fields to their initial values. This allows the user to start over with a fresh form.
阅读全文