FxMention 提及输入框
用于在输入中提及某人或某物(@ 提及)。不依赖任何 UI 框架,继承 FxInput 全部能力,内部组合 FxTooltip + FxScrollbar + 下拉面板,支持自定义前缀、textarea、远程搜索、整体删除、自定义模板与 header/footer。
基础用法
输入 @ 触发提及,按 ↑ / ↓ 选择,Enter 确认,Esc 关闭。
自定义选项别名
通过 props 属性自定义 options 的字段别名(默认为 { value: 'value', label: 'label', disabled: 'disabled' })。
多行输入
设置 type="textarea" 切换为多行输入,光标定位同样有效。
自定义选项模板
通过 label 插槽自定义选项内容,作用域内可访问 item 与 index。
远程搜索
监听 search 事件异步拉取选项,配合 loading 显示加载态。
自定义前缀
通过 prefix 自定义触发前缀,默认 @;支持 string[] 配置多个前缀。
整体删除
设置 whole 为 true,退格时会将提及内容整体删除;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 | 弹层是否显示箭头 | boolean | false |
| offset | 弹层偏移量 | number | 0 |
| whole | 退格删除时是否将提及内容整体删除 | boolean | false |
| check-is-whole | 退格删除时判断是否为整体提及 | (pattern: string, prefix: string) => boolean | — |
| loading | 弹层是否加载中 | boolean | false |
| model-value (v-model) | 输入值 | string | — |
| popper-class | 弹层自定义类名 | string / array / object | — |
| popper-style | 弹层自定义样式 | string / CSSProperties | — |
| popper-options | floating-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
| 名称 | 说明 | 类型 |
|---|---|---|
| input | FxInput 实例 | Ref<FxInputInstance | null> |
| tooltip | FxTooltip 实例 | 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
}