Skip to content

InputTag 标签输入 ​

输入即提交的标签组,支持触发键、上限、去重与点删。

基础用法 ​

vue
<script setup>
import { ref } from 'vue'
const tags = ref(['水墨', '留白'])
</script>

<template>
  <lh-input-tag v-model="tags" placeholder="输入后按回车提交" />
</template>

触发键 ​

trigger 支持 enter(默认)/ space / comma。space / comma 触发时空白不进入输入框。

vue
<template>
  <lh-input-tag v-model="tags" trigger="comma" placeholder="输入逗号提交" />
</template>

上限与去重 ​

vue
<template>
  <lh-input-tag v-model="tags" :max="3" allow-duplicate />
</template>

max 为正数时限上限(超限不提交,输入被清空);默认不允许重复(重复不提交)。

只读与禁用 ​

vue
<template>
  <lh-input-tag v-model="tags" readonly />
  <lh-input-tag v-model="tags" disabled />
</template>

Props ​

属性说明类型默认值
modelValue标签列表(v-model)string[][]
trigger提交触发键(小程序端一律走完成键)'enter' | 'space' | 'comma''enter'
placeholder占位提示(仅无标签时显示)string''
placeholderStyle占位样式(替代 ::placeholder)string—
max标签上限(非正数不限)number0
allowDuplicate允许重复标签booleanfalse
readonly只读booleanfalse
disabled禁用booleanfalse
ariaLabel无障碍名称string—
customClass自定义类名string—
sx快速布局属性LhSxProps—

Events ​

事件说明参数
update:modelValue标签列表变化(value: string[])
change标签列表变化(同 modelValue)(value: string[])
add提交单个标签(tag: string)
remove移除单个标签(tag: string)

方法(defineExpose) ​

方法说明
focus聚焦输入框
commit提交当前输入

平台差异 ​

能力H5小程序
提交触发键trigger 全支持(Enter / Space / Comma 键盘事件)一律走完成键(@confirm);space / comma 触发键语义仅 H5
Backspace 删尾输入为空时按 Backspace 删最后一个标签无键盘事件,删除走标签的 × 按钮(双端可用)
失焦提交有有
聚焦边框:has() 聚焦样式生效聚焦边框不可用(WXSS 不支持 :has()),输入正常