InputTag 標籤輸入
LhInputTag 標籤輸入框:Enter 生成標籤,Backspace 刪除尾項。
基礎用法
基礎用法
VueVite
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhInputTag } from '@lh-ui/vue3'
const tags = ref(['Vue', 'Vite'])
const t1 = {
placeholder: '輸入標籤後 Enter',
}
</script>
<template>
<LhInputTag v-model="tags" :placeholder="t1.placeholder" />
</template>vue
<script>
import { LhInputTag } from '@lh-ui/vue3'
export default {
components: { LhInputTag },
data() {
return {
tags: ['Vue', 'Vite'],
t1: {
placeholder: '輸入標籤後 Enter',
},
}
},
}
</script>
<template>
<LhInputTag v-model="tags" :placeholder="t1.placeholder" />
</template>觸發鍵與上限
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhInputTag } from '@lh-ui/vue3'
const tags2 = ref([])
const t2 = {
placeholder2: '空格觸發,最多 5 個',
}
</script>
<template>
<LhInputTag v-model="tags2" trigger="space" :max="5" :placeholder="t2.placeholder2" />
</template>vue
<script>
import { LhInputTag } from '@lh-ui/vue3'
export default {
components: { LhInputTag },
data() {
return {
tags2: [],
t2: {
placeholder2: '空格觸發,最多 5 個',
},
}
},
}
</script>
<template>
<LhInputTag v-model="tags2" trigger="space" :max="5" :placeholder="t2.placeholder2" />
</template>InputTag API
屬性
| 屬性名 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| modelValue | 標籤列表 | string[] | [] |
| trigger | 提交觸發鍵 | LhInputTagTrigger | 'enter' |
| placeholder | 佔位提示 | string | '' |
| max | 標籤上限 | number | 0 |
| allowDuplicate | 允許重複標籤 | boolean | false |
| readonly | 唯讀 | boolean | false |
| disabled | 停用 | boolean | false |
| ariaLabel | 無障礙名稱 | string | — |
| sx | 快速版面配置屬性 | LhSxProps | — |
事件
| 屬性名 | 說明 | 類型 |
|---|---|---|
| update:modelValue | 標籤列表變化時觸發 | (value: string[]) |
| change | 標籤列表變化時觸發 | (value: string[]) |
| add | 提交單個標籤時觸發 | (tag: string) |
| remove | 移除單個標籤時觸發 | (tag: string) |
無障礙
- 輸入框帶
aria-label - 輸入為空時 Backspace 刪除尾項

