Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào ứng dụng đã cài registry, hoặc mở trong StackBlitz.
Thêm và xóa tag
Enter thêm chữ thành tag; dấu × xóa một tag.
TagsInputBasic.vue
<script setup lang="ts">
import { ref } from 'vue'
import { TagsInput, TagsInputInput, TagsInputItem, TagsInputItemDelete, TagsInputItemText } from '@/components/ui/tags-input'
const tags = ref(['mùa hè', 'bán chạy', 'miễn phí giao hàng'])
</script>
<template>
<div class="grid w-full max-w-96 gap-(--bh-space-100)">
<label for="product-tags" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Tag sản phẩm</label>
<TagsInput v-model="tags">
<TagsInputItem v-for="tag in tags" :key="tag" :value="tag">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput id="product-tags" placeholder="Thêm tag…" aria-describedby="product-tags-hint" />
</TagsInput>
<p id="product-tags-hint" class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">Nhấn Enter sau mỗi tag.</p>
</div>
</template>Địa chỉ email
Dấu phẩy hoặc dán thêm nhiều địa chỉ cùng lúc.
Tối đa 5 địa chỉ. Có thể dán danh sách cách nhau bằng dấu phẩy.
TagsInputEmails.vue
<script setup lang="ts">
import { ref } from 'vue'
import { TagsInput, TagsInputInput, TagsInputItem, TagsInputItemDelete, TagsInputItemText } from '@/components/ui/tags-input'
const recipients = ref(['[email protected]', '[email protected]'])
</script>
<template>
<div class="grid w-full max-w-96 gap-(--bh-space-100)">
<label for="alert-recipients" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Gửi cảnh báo đồng bộ tới</label>
<TagsInput v-model="recipients" :max="5" delimiter="," add-on-paste add-on-blur>
<TagsInputItem v-for="email in recipients" :key="email" :value="email">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput id="alert-recipients" type="email" placeholder="[email protected]" aria-describedby="alert-recipients-hint" />
</TagsInput>
<p id="alert-recipients-hint" class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">Tối đa 5 địa chỉ. Có thể dán danh sách cách nhau bằng dấu phẩy.</p>
</div>
</template>Vô hiệu
Tag vẫn đọc được.
Kênh bán hàng lấy từ CRM. Hãy đổi trong CRM.
TagsInputDisabled.vue
<script setup lang="ts">
import { TagsInput, TagsInputInput, TagsInputItem, TagsInputItemDelete, TagsInputItemText } from '@/components/ui/tags-input'
const channels = ['Cửa hàng online', 'Sàn A']
</script>
<template>
<div class="grid w-full max-w-96 gap-(--bh-space-100)">
<label for="sales-channels" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Kênh bán hàng</label>
<TagsInput :model-value="channels" disabled>
<TagsInputItem v-for="channel in channels" :key="channel" :value="channel">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput id="sales-channels" aria-describedby="sales-channels-hint" />
</TagsInput>
<p id="sales-channels-hint" class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">Kênh bán hàng lấy từ CRM. Hãy đổi trong CRM.</p>
</div>
</template>