mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-02-03 05:37:56 +01:00
docs(form): specify component ref type (#2296)
This commit is contained in:
@@ -117,23 +117,28 @@ You can manually set errors after form submission if required. To do this, simpl
|
|||||||
|
|
||||||
```vue
|
```vue
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { FormError, FormSubmitEvent } from '#ui/types'
|
import type { Form, FormSubmitEvent } from '#ui/types'
|
||||||
|
|
||||||
const state = reactive({
|
interface Schema {
|
||||||
|
email?: string
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = reactive<Schema>({
|
||||||
email: undefined,
|
email: undefined,
|
||||||
password: undefined
|
password: undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
const form = ref()
|
const form = ref<Form<Schema>>()
|
||||||
|
|
||||||
async function onSubmit (event: FormSubmitEvent<any>) {
|
async function onSubmit (event: FormSubmitEvent<Schema>) {
|
||||||
form.value.clear()
|
form.value!.clear()
|
||||||
try {
|
try {
|
||||||
const response = await $fetch('...')
|
const response = await $fetch('...')
|
||||||
// ...
|
// ...
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.statusCode === 422) {
|
if (err.statusCode === 422) {
|
||||||
form.value.setErrors(err.data.errors.map((err) => ({
|
form.value!.setErrors(err.data.errors.map((err) => ({
|
||||||
// Map validation errors to { path: string, message: string }
|
// Map validation errors to { path: string, message: string }
|
||||||
message: err.message,
|
message: err.message,
|
||||||
path: err.path,
|
path: err.path,
|
||||||
|
|||||||
Reference in New Issue
Block a user