Skip to content

Mentions

Rules

Basic Example

js
const rule = {
    type:"aMentions",
    title:"Mention",
    field:"mention",
    modelField: "value",
    value: "hello @Jeremy",
    props: {
        options: [
            {
                label: 'Fuphoenixes',
                value: 'Fuphoenixes',
            },
            {
                label: 'kooriookami',
                value: 'kooriookami',
            },
            {
                label: 'Jeremy',
                value: 'Jeremy',
            },
            {
                label: 'btea',
                value: 'btea',
            }
        ]
    }
}

Props Configuration Examples

Custom Trigger Prefix

js
const rule = {
    type:"aMentions",
    title:"@User",
    field:"content",
    modelField: "value",
    value: "",
    props: {
        prefix: '#',
        options: [
            {label: 'Topic 1', value: 'topic1'},
            {label: 'Topic 2', value: 'topic2'},
        ],
        placeholder: "Type # to mention a topic",
    },
}

Remote Load Options

js
const rule = {
    type:"aMentions",
    title:"@User",
    field:"content",
    modelField: "value",
    value: "",
    inject: true,
    props: {
        prefix: '@',
        options: [],
        placeholder: "Type @ to mention a user",
    },
    on: {
        search: ($inject, value, prefix) => {
            // Remote search users
            if (prefix === '@' && value) {
                searchUsers(value).then(res => {
                    $inject.self.props.options = res.data.map(user => ({
                        label: user.name,
                        value: user.id
                    }));
                });
            }
        },
    },
}

Events Examples

Listen to Mention Events

js
const rule = {
    type:"aMentions",
    title:"Comment",
    field:"comment",
    modelField: "value",
    value: "",
    props: {
        prefix: '@',
        options: [
            {label: 'Zhang San', value: '1'},
            {label: 'Li Si', value: '2'},
        ],
    },
    on: {
        search: (value, prefix) => {
            console.log('Search mention:', value, prefix);
        },
        select: (option, prefix) => {
            console.log('Select mention:', option, prefix);
        },
        change: (value) => {
            console.log('Content changed:', value);
        },
        focus: () => {
            console.log('Component focused');
        },
        blur: () => {
            console.log('Component blurred');
        },
    },
}

Complete configuration items: Ant-design-vue_Mentions

value :Number

Props

ParameterDescriptionTypeDefault
autofocusAuto focusbooleanfalse
filterOptionCustom filter logicfalse | (input: string, option: OptionProps) => boolean
getPopupContainerSpecify HTML node where suggestion box is mounted() => HTMLElement
notFoundContentContent displayed when dropdown list is emptystring | slot'Not Found'
placementDisplay position of popup layertop | bottombottom
prefixSet trigger keywordstring | string[]'@'
splitSet separator before and after selected itemstring' '
statusSet validation status'error' | 'warning'-
validateSearchCustom trigger validation logic(text: string, props: MentionsProps) => void
optionsOption configurationOptions[]
optionCustom node through option slotv-slot:option="option"-

Events

Event NameDescriptionCallback Parameters
blurCallback when losing focusfunction
changeTriggered when value changesfunction(value: string)
focusCallback when gaining focusfunction
searchCallback when text box value changesfunction(value: string, prefix: string)
selectTriggered when option is selectedfunction(option: OptionProps, prefix: string)

Option

ParameterDescriptionTypeDefault
valueValue filled when selectedstringnumber
labelTitle of optionVueNode(o: Option)=> VueNode
disabledWhether selectableboolean-
classcss class namestring-
styleOption styleCSSProperties-
payloadOther dataobject-

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.