Vue-At: @-Mentions for Vue.js

3.0.0-alpha.3 · active · verified Sun Apr 19

vue-at is a JavaScript library that provides robust '@'-mentioning functionality, similar to At.js, but specifically engineered for Vue applications without relying on jQuery or injecting additional DOM nodes. It offers a lightweight and stable alternative for implementing user mentions in input fields. The library supports various Vue versions, including dedicated branches for Vue 1 (`vue-at@1.x` or `vue1-at`), Vue 2 (`vue-at@2.x`), and the current development focus, Vue 3 (`vue-at@next`, which is currently `3.0.0-alpha.3`). It is actively maintained with ongoing development for the latest Vue ecosystem. Key differentiating features include its plain-text based core, native support for both `contenteditable` divs and `textarea` elements, and extensive customization options for member lists and display templates. It also boasts compatibility with popular UI frameworks such as Vuetify and Element UI.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates both the `At` (for contenteditable) and `AtTa` (for textarea) components, showcasing basic `@`-mentioning with a list of members and `v-model` binding for two-way data synchronization. It includes essential styling for the mention dropdown.

<template>
  <at :members="members" v-model="message">
    <div contenteditable style="border: 1px solid #ccc; padding: 8px; min-height: 50px;"></div>
  </at>
  <p>Current message: {{ message }}</p>

  <at-ta :members="members" v-model="textareaMessage" style="margin-top: 20px;">
    <textarea style="width: 100%; height: 80px; padding: 8px; border: 1px solid #ccc;"></textarea>
  </at-ta>
  <p>Current textarea message: {{ textareaMessage }}</p>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import At from 'vue-at';
import AtTa from 'vue-at/dist/vue-at-textarea';

// Ensure 'textarea-caret' is installed: npm i -S textarea-caret

const message = ref('');
const textareaMessage = ref('');

const members = ref([
  'Alice',
  'Bob',
  'Charlie',
  'David',
  { name: 'Eve', display: 'Eve (Admin)' },
  'Frank',
  'Grace'
]);
</script>

<style>
.atwho-view {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 99999999;
  display: none;
  background: white;
  border: 1px solid #eee;
  font-size: 14px;
  list-style: none;
  padding: 0;
  margin: 0;
  border-radius: 3px;
  box-shadow: 0 5px 10px rgba(0,0,0,.1);
  min-width: 120px;
}

.atwho-view ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.atwho-view li {
  display: block;
  padding: 5px 10px;
  cursor: pointer;
}

.atwho-view strong {
  color: #66CCFF;
}

.atwho-view li.cur {
  background: #66CCFF;
  color: white;
}
</style>

view raw JSON →