Getting Started with the Vue Mention Component in Vue 2

30 Jul 20266 minutes to read

This article provides a step-by-step guide for setting up a Vue 2 project using Vue-CLI and integrating the Syncfusion® Vue Mention component.

To get started quickly with Vue Mention, check this video:

Prerequisites

System requirements for Syncfusion® Vue UI components

Setup the Vue 2 project

Easily set up a Vue 2 application using Vue CLI, which provides a reliable development environment, a streamlined project structure, and optimized builds compared to older setup tools. For detailed steps, refer to the Vue CLI installation instructions.

Note: To create a Vue 2 application using Vue CLI, refer to this documentation for more details.

To create a new Vue 2 application, run the following commands based on your preferred package manager:

npm install -g @vue/cli
vue create quickstart

or

yarn global add @vue/cli
vue create quickstart

During the setup process, the CLI will prompt you for a few configuration options. Select the following:

  • Which linter to use?Default ([Vue 2] babel, eslint)
  • Install with npm and start now?Yes

Selecting Yes automatically installs the project dependencies and starts the development server.

After verifying that the application starts successfully, terminate the development server in the terminal and proceed to the next step.

Navigate to the project directory:

cd quickstart

Adding Vue Dropdowns package

To install the Dropdowns package, use the following command:

npm install @syncfusion/ej2-vue-dropdowns

or

yarn add @syncfusion/ej2-vue-dropdowns

Adding CSS reference

Themes for Syncfusion® Dropdown components can be applied using CSS files provided through npm theme packages. For available themes, refer to the Themes documentation.

Install the Material 3 theme package using the following command:

npm install @syncfusion/ej2-material3-theme --save

Then add the following CSS reference to the src/App.vue file:

<style>
  @import "../node_modules/@syncfusion/ej2-material3-theme/styles/mention/index.css";
</style>

You can also refer to the combined CSS file for all Syncfusion components in your application. For more information, see the documentation on referring themes through npm packages.

Adding Mention component

Now, you can add the Vue Mention component to your src/App.vue file by importing and defining it within your application. To use the Mention component properly, the target property should be configured so that it renders the Mention component in the configured element.

After initialization, populate the Mention with data using the dataSource property. Here, an array of string values is passed to the Mention component. Use the following code:

<template>
    <div id="app">
        <label id="comment">Comments</label>
        <div id="mentionElement" placeholder="Type @ and tag user"></div>
        <ejs-mention id='defaultMention' :target='mentionTarget' :dataSource='userData'></ejs-mention>
    </div>
</template>

<script>
    import { MentionComponent } from "@syncfusion/ej2-vue-dropdowns";
    export default {
        components: {
            'ejs-mention': MentionComponent
        },
        name: 'app',
        data: function () {
            return {
                mentionTarget: "#mentionElement",
                userData: ['Selma Rose', 'Garth', 'Robert', 'William', 'Joseph']
            };
        }
    }
</script>

<style>
    @import "../node_modules/@syncfusion/ej2-material3-theme/styles/mention/index.css";

    #app {
        color: #008cff;
        height: 40px;
        left: 15%;
        position: absolute;
        top: 10%;
        width: 30%;
    }

    #comment {
        font-size: 15px;
        font-weight: 600;
    }

    #mentionElement {
        min-height: 100px;
        border: 1px solid #D7D7D7;
        border-radius: 4px;
        padding: 8px;
        font-size: 14px;
        width: 600px;
    }

    div#mentionElement[placeholder]:empty:before {
        content: attr(placeholder);
        color: #555;
    }
</style>

Run the application

To run the application, use the following command:

npm run dev

or

yarn run serve

The output will appear as follows:

You can refer to our Vue Mention feature tour page for its groundbreaking feature representations. You can also explore our Vue Mention example that shows how to render the Mention in Vue.

See also