68 lines
2.0 KiB
Vue
68 lines
2.0 KiB
Vue
<script setup lang="ts">
|
|
import {
|
|
Button,
|
|
Description,
|
|
FieldError,
|
|
FieldGroup,
|
|
Fieldset,
|
|
FieldsetLegend,
|
|
FieldsetActions,
|
|
Form,
|
|
Input,
|
|
Label,
|
|
TextArea,
|
|
TextField,
|
|
} from "@heroui-vue/components";
|
|
import { IconDeviceFloppy } from "@tabler/icons-vue";
|
|
import { ref } from "vue";
|
|
const result = ref("");
|
|
function validateName(value: string) {
|
|
return value.length < 3 ? "姓名至少需要 3 个字符" : null;
|
|
}
|
|
function validateBio(value: string) {
|
|
return value.length < 10 ? "简介至少需要 10 个字符" : null;
|
|
}
|
|
function submit(event: Event) {
|
|
const data = Object.fromEntries(
|
|
new FormData(event.currentTarget as HTMLFormElement),
|
|
);
|
|
result.value = `表单提交成功!${JSON.stringify(data)}`;
|
|
}
|
|
</script>
|
|
<template>
|
|
<Form class="w-full max-w-96" @submit.prevent="submit">
|
|
<Fieldset>
|
|
<FieldsetLegend>个人资料设置</FieldsetLegend>
|
|
<Description>更新你的个人资料信息。</Description>
|
|
<FieldGroup>
|
|
<TextField is-required name="name" :validate="validateName">
|
|
<Label>姓名</Label>
|
|
<Input placeholder="John Doe" />
|
|
<FieldError />
|
|
</TextField>
|
|
<TextField is-required name="email" type="email">
|
|
<Label>邮箱</Label>
|
|
<Input placeholder="john@example.com" />
|
|
<FieldError />
|
|
</TextField>
|
|
<TextField is-required name="bio" :validate="validateBio">
|
|
<Label>简介</Label>
|
|
<TextArea placeholder="介绍一下你自己…" />
|
|
<Description>至少 10 个字符</Description>
|
|
<FieldError />
|
|
</TextField>
|
|
</FieldGroup>
|
|
<FieldsetActions>
|
|
<Button type="submit">
|
|
<IconDeviceFloppy aria-hidden="true" />
|
|
保存更改
|
|
</Button>
|
|
<Button type="reset" variant="secondary" @click="result = ''">
|
|
取消
|
|
</Button>
|
|
</FieldsetActions>
|
|
</Fieldset>
|
|
<p v-if="result" class="text-sm text-muted" role="status">{{ result }}</p>
|
|
</Form>
|
|
</template>
|