Skip to content

FxMention 提及输入框

用于在输入中提及某人或某物(@ 提及)。不依赖任何 UI 框架,继承 FxInput 全部能力,内部组合 FxTooltip + FxScrollbar + 下拉面板,支持自定义前缀、textarea、远程搜索、整体删除、自定义模板与 header/footer。

基础用法

输入 @ 触发提及,按 / 选择,Enter 确认,Esc 关闭。

自定义选项别名

通过 props 属性自定义 options 的字段别名(默认为 { value: 'value', label: 'label', disabled: 'disabled' })。

多行输入

设置 type="textarea" 切换为多行输入,光标定位同样有效。

自定义选项模板

通过 label 插槽自定义选项内容,作用域内可访问 itemindex

远程搜索

监听 search 事件异步拉取选项,配合 loading 显示加载态。

自定义前缀

通过 prefix 自定义触发前缀,默认 @;支持 string[] 配置多个前缀。

整体删除

设置 wholetrue,退格时会将提及内容整体删除;check-is-whole 可自定义判断逻辑(常用于远程选项场景)。

配合表单

FxForm 配合使用,支持校验。

TIP

本组件基于 FxInput 开发,原输入框属性不变,此处不再重复,请前往原组件查看文档。

API

Attributes

属性说明类型默认值
options提及选项列表MentionOption[][]
props选项字段别名配置MentionOptionProps{ value: 'value', label: 'label', disabled: 'disabled' }
prefix触发提及的前缀字符(长度须为 1);支持多前缀string / string[]'@'
split分隔提及的字符(长度须为 1)string' '
filter-option自定义过滤逻辑;传 false 关闭过滤false / ((pattern: string, option: MentionOption) => boolean)内置大小写不敏感包含匹配
placement弹层方位'bottom' / 'top''bottom'
show-arrow弹层是否显示箭头booleanfalse
offset弹层偏移量number0
whole退格删除时是否将提及内容整体删除booleanfalse
check-is-whole退格删除时判断是否为整体提及(pattern: string, prefix: string) => boolean
loading弹层是否加载中booleanfalse
model-value (v-model)输入值string
popper-class弹层自定义类名string / array / object
popper-style弹层自定义样式string / CSSProperties
popper-optionsfloating-ui 参数object
input 属性

Events

事件名说明类型
search命中前缀时触发(pattern: string, prefix: string) => void
select选中某个选项时触发(option: MentionOption, prefix: string) => void
whole-remove整体提及被删除时触发(whole 为 true 或 check-is-whole 返回 true)(pattern: string, prefix: string) => void
update:modelValue绑定值更新(value: string) => void
input输入时(value: string) => void
focus聚焦(event: FocusEvent) => void
blur失焦(event: FocusEvent) => void
input 事件

Slots

插槽名说明类型
label自定义选项内容{ item: MentionOption, index: number }
loading自定义加载内容
header下拉顶部内容
footer下拉底部内容
input 插槽

Exposes

名称说明类型
inputFxInput 实例Ref<FxInputInstance | null>
tooltipFxTooltip 实例Ref<FxTooltipInstance | null>
dropdownVisible下拉显隐状态ComputedRef<boolean>

类型声明

展开声明
ts
type MentionOption = {
  value?: string
  label?: string
  disabled?: boolean
  [key: string]: any
}

type MentionOptionProps = {
  value?: string
  label?: string
  disabled?: string
  [key: string]: string | undefined
}