Vue Select Component
Vue Select is a lightweight, extensible Vue component designed to replace the native HTML `<select>` element, offering enhanced features like filtering, tagging, and AJAX support. The project currently maintains two major lines: the stable version 3.x (latest 3.20.4), which exclusively supports Vue 2, and the actively developed beta channel 4.x (currently 4.0.0-beta.6), which targets Vue 3. While version 3.x receives maintenance updates for critical bug fixes, the primary development effort is focused on the Vue 3 compatible 4.x branch. It differentiates itself by being dependency-free at runtime (aside from Vue itself), highly customizable via slots and SCSS variables, and built with strong emphasis on accessibility. Releases for v3.x have become less frequent as v4.x development progresses towards a stable release, which will likely become the new default for Vue 3 projects.
Common errors
-
[Vue warn]: Unknown custom element: <v-select> - did you register the component correctly?
cause The `v-select` component was not globally registered or locally imported/declared in the component where it's being used, or an incorrect import/register method was used for the respective Vue/vue-select version.fixEnsure you have correctly registered the component globally (e.g., `Vue.component('v-select', vSelect)` for Vue 2 or `app.component('v-select', VueSelect)` for Vue 3) or declared it in the `components` option of your Vue component. -
The v-select component appears unstyled or broken, showing default HTML elements.
cause The required CSS file for `vue-select` has not been imported into your project.fixAdd `import 'vue-select/dist/vue-select.css';` to your main JavaScript/TypeScript entry file, or use `@import 'vue-select/dist/vue-select.css';` in a global stylesheet or component style block. -
TypeError: Cannot read properties of undefined (reading 'install') during Vue.use() or similar.
cause Attempting to install `vue-select` as a Vue plugin (e.g., `Vue.use(vSelect)`), which it is not. `vue-select` is a component, not a plugin with an `install` method.fixDo not use `Vue.use()` with `vue-select`. Instead, register it directly as a component: `Vue.component('v-select', vSelect)` for Vue 2, or `app.component('v-select', VueSelect)` for Vue 3.
Warnings
- breaking Vue Select has separate major versions for Vue 2 (v3.x) and Vue 3 (v4.x). Installing `vue-select` defaults to v3.x (Vue 2), while `vue-select@beta` installs v4.x (Vue 3). Ensure you install the correct version for your Vue project.
- breaking The component's default export/named export changed between v3.x and v4.x. v3.x uses a default export (`import vSelect from 'vue-select'`), while v4.x uses a named export (`import { VueSelect } from 'vue-select'`).
- gotcha Vue Select does not include its CSS by default. You must explicitly import the stylesheet for the component to render correctly and be styled.
- deprecated While CommonJS `require()` might still work in some environments, it is generally recommended to use ES Module `import` syntax for modern Vue applications, especially when dealing with Vue 3 projects.
- gotcha The v4.x version for Vue 3 is currently in beta. While generally stable, it might contain minor bugs or experience breaking changes before its stable release. Use with caution in production environments.
Install
-
npm install vue-select -
yarn add vue-select -
pnpm add vue-select
Imports
- vSelect (Vue 2)
import { vSelect } from 'vue-select'import vSelect from 'vue-select'
- VueSelect (Vue 3)
import VueSelect from 'vue-select'
import { VueSelect } from 'vue-select' - CSS Styles
require('vue-select/dist/vue-select.css')import 'vue-select/dist/vue-select.css';
Quickstart
import { createApp } from 'vue';
import App from './App.vue';
import { VueSelect } from 'vue-select';
import 'vue-select/dist/vue-select.css';
createApp(App)
.component('v-select', VueSelect)
.mount('#app');
// In App.vue template:
// <template>
// <div id="app">
// <v-select :options="['Canada', 'United States', 'Mexico']"></v-select>
// </div>
// </template>