ant ui 抽屉 表单功能 --(头部校验可滚动到对应区域)——
<template>
<a-drawer :open="visible" :title="title" @close="onClose">
<a-form
id="aaa_form"
ref="formRef"
:model="form"
:rules="rules"
:scroll-to-first-error="true"
>
<a-row :gutter="16">
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="Description" name="description">
<a-textarea
v-model:value="form.description"
:rows="4"
placeholder="Please enter url description"
/>
</a-form-item>
</a-col>
</a-row>
<a-space>
<a-button @click="onClose">Cancel</a-button>
<a-button type="primary" @click="onSubmit" html-type="submit"
>Submit</a-button
>
</a-space>
</a-form>
<template #extra>
<a-space>
<a-button @click="onClose">Cancel</a-button>
<a-button
type="primary"
form="aaa_form"
@click="onSubmit"
html-type="submit"
>Submit</a-button
>
</a-space>
</template>
</a-drawer>
</template>
<script setup>
import { ref } from "vue";
const visible = ref(true);
const title = "Drawer Title";
const form = ref({
description: "",
});
const formRef = ref(null);
const rules = {
description: [
{
required: true,
message: "Please enter the description",
trigger: "blur",
},
],
};
function onClose() {
visible.value = false;
}
async function onSubmit() {
try {
await formRef.value.validate();
console.log("Form values:", form.value);
onClose(); // Close the drawer after successful submission
} catch (error) {
console.error("Error:", error);
}
}
</script>