外观
TagsInput 标签输入框
输入多个标签,按回车提交新标签,也可逐个删除已有标签。
import { STagsInput } from '@icecreamqaq/shadcn/tags-input'使用示例
基础用法
tags-input.vue组合式 API vue
<template>
<s-tags-input v-model="tags" :max="5">
<s-tags-input-item v-for="tag in tags" :key="tag" :value="tag">
<s-tags-input-item-text />
<s-tags-input-item-delete :aria-label="'移除' + tag" />
</s-tags-input-item>
<s-tags-input-input aria-label="项目标签" placeholder="输入标签,按回车添加" />
</s-tags-input>
</template>
<script setup lang="ts">
import { ref } from "vue"
import { STagsInput, STagsInputInput, STagsInputItem, STagsInputItemDelete, STagsInputItemText } from "@icecreamqaq/shadcn/tags-input"
const tags = ref(["设计", "待评审"])
</script>vue
<template>
<s-tags-input v-model="tags" :max="5">
<s-tags-input-item v-for="tag in tags" :key="tag" :value="tag">
<s-tags-input-item-text />
<s-tags-input-item-delete :aria-label="'移除' + tag" />
</s-tags-input-item>
<s-tags-input-input aria-label="项目标签" placeholder="输入标签,按回车添加" />
</s-tags-input>
</template>
<script lang="ts">
import { defineComponent } from "vue"
import { STagsInput, STagsInputInput, STagsInputItem, STagsInputItemDelete, STagsInputItemText } from "@icecreamqaq/shadcn/tags-input"
export default defineComponent({
components: { STagsInput, STagsInputInput, STagsInputItem, STagsInputItemDelete, STagsInputItemText },
data() {
return { tags: ["设计", "待评审"] }
},
})
</script>常用 API
| 成员 | 类型 | 用法 |
|---|---|---|
STagsInput.v-model | 标签值数组 | 默认存储字符串数组,新增和删除都会更新模型。 |
STagsInput.max | number | 限制最多可添加的标签数,0 表示无限制。 |
STagsInput.delimiter | string | RegExp | 定义拆分多个值的分隔符,默认为英文逗号。add-on-paste 可启用粘贴拆分。 |
STagsInputItem.value | 标签值 | 标识当前已有标签。在项内组合 STagsInputItemText 和 STagsInputItemDelete。 |
完整 API
TagsInput23 个成员
属性
| 名称 | 类型 |
|---|---|
modelValue | AcceptableInputValue[] | null |
defaultValue | AcceptableInputValue[] |
addOnPaste | boolean |
addOnTab | boolean |
addOnBlur | boolean |
duplicate | boolean |
disabled | boolean |
delimiter | string | RegExp |
dir | Direction |
max | number |
id | string |
convertValue | ((value: string) => AcceptableInputValue) |
displayValue | ((value: AcceptableInputValue) => string) |
asChild | boolean |
as | AsTag | Component |
name | string |
required | boolean |
class | ClassValue |
事件
| 名称 | 类型 |
|---|---|
invalid | ((payload: AcceptableInputValue) => any) |
update:modelValue | ((payload: AcceptableInputValue[]) => any) |
addTag | ((payload: AcceptableInputValue) => any) |
removeTag | ((payload: AcceptableInputValue) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: { modelValue: AcceptableInputValue[]; }) => any) |
TagsInputInput6 个成员
属性
| 名称 | 类型 |
|---|---|
placeholder | string |
autoFocus | boolean |
maxLength | number |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
TagsInputItem7 个成员
属性
| 名称 | 类型 |
|---|---|
value 必填 | AcceptableInputValue |
modelIndex | number |
disabled | boolean |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
TagsInputItemDelete4 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
TagsInputItemText4 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
分组导出
模板标签为 <s-tags-input>。
组件 STagsInput、STagsInputInput、STagsInputItem、STagsInputItemDelete、STagsInputItemText