Files
heroui-vue/apps/docs/demos/switch-form.vue
T

58 lines
1.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
SwitchGroup,
Button,
} from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) {
const values = [...new FormData(event.target as HTMLFormElement).entries()];
result.value = values.length
? "表单提交内容:" + values.map(([k, v]) => `${k}: ${v}`).join(",")
: "未选择任何选项";
}
</script>
<template>
<form class="flex flex-col gap-4" @submit.prevent="submit">
<SwitchGroup>
<Switch name="notifications" value="on">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
启用通知
</SwitchContent>
</Switch>
<Switch default-selected name="newsletter" value="on">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
订阅新闻简报
</SwitchContent>
</Switch>
<Switch name="marketing" value="on">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
接收营销更新
</SwitchContent>
</Switch>
</SwitchGroup>
<div class="flex gap-2">
<Button class="mt-4" size="sm" type="submit">Submit</Button>
<Button
class="mt-4"
size="sm"
type="reset"
variant="secondary"
@click="result = ''"
>
重置
</Button>
</div>
<output v-if="result" class="text-sm text-muted" aria-live="polite">
{{ result }}
</output>
</form>
</template>