Install vue-multiselect
masterInstall the vue-multiselect package via npm to use it in your Vue 3 project.
npm install vue-multiselectrepository·master·Indexed 27 days ago
https://github.com/shentao/vue-multiselectA highly configurable, dependency-free selection component for Vue 3. It supports single and multiple selection, tagging, searching, and asynchronous data loading. Version 3.5.0.
Install the vue-multiselect package via npm to use it in your Vue 3 project.
npm install vue-multiselectIf you encounter issues where the Vue Options API appears disabled, it may be due to @vitejs/plugin-vue version 5.2.2 or later. To resolve this, downgrade to version 5.2.1.
npm install @vitejs/plugin-vue@5.2.1To enable searching in a single select component, use v-model and set :searchable (default behavior) while managing :close-on-select and :clear-on-select.
<VueMultiselect
v-model="value"
:options="source"
:close-on-select="true"
:clear-on-select="false"
placeholder="Select one"
label="name"
track-by="name"
/>To allow users to create new tags that aren't in the original options list:
:taggable="true".:multiple="true" (optional, but common for tags).@tag event to handle the creation of the new tag and update your options and model.tag-placeholder to customize the text shown when typing a new tag.<VueMultiselect
v-model="taggingSelected"
:options="taggingOptions"
:multiple="true"
:taggable="true"
@tag="addTag"
tag-placeholder="Add this as new tag"
placeholder="Type to search or add tag"
label="name"
track-by="code"
/>addTag (newTag) {
const tag = {
name: newTag,
code: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000))
}
this.taggingOptions.push(tag)
this.taggingSelected.push(tag)
}For loading options from an external service based on user input:
@search-change event.query and update the :options array.#noResult slot to display a custom message when no items match the query.<VueMultiselect
v-model="selectedCountries"
:options="countries"
:multiple="multiple"
:searchable="searchable"
@search-change="asyncFind"
placeholder="Type to search"
label="name"
track-by="code"
>
<template #noResult>
Oops! No elements found. Consider changing the search query.
</template>
</VueMultiselect>methods: {
asyncFind (query) {
this.countries = findService(query)
}
}To allow selecting multiple items, add the :multiple="true" prop.
<VueMultiselect
v-model="multiValue"
:options="source"
:multiple="true"
:close-on-select="true"
placeholder="Pick some"
label="name"
track-by="name"
/>Use the following props to configure a single select dropdown without search functionality:
:model-value: The current value.:options: The list of options.:searchable="false": Disables search.:close-on-select="false": Keeps the dropdown open after selection.:allow-empty="false": Prevents clearing the selection.label: The property name to display in the list.track-by: The property name used to track the selected item.<VueMultiselect
:model-value="value"
:options="source"
:searchable="false"
:close-on-select="false"
:allow-empty="false"
@update:model-value="updateSelected"
label="name"
placeholder="Select one"
track-by="name"
/>To use VueMultiselect, import the component, register it in your component's components object, and provide v-model and :options. You must also import the component's CSS file.
<template>
<div>
<VueMultiselect
v-model="selected"
:options="options">
</VueMultiselect>
</div>
</template>
<script>
import VueMultiselect from 'vue-multiselect'
export default {
components: { VueMultiselect },
data () {
return {
selected: null,
options: ['list', 'of', 'options']
}
}
}
</script>
<style src="vue-multiselect/dist/vue-multiselect.css"></style>Multiselect component is the primary entry point for using the library. You can import it as a default export or as a named export from the package.multiselectMixin is exported for developers who need to extend or replicate the core multiselect logic in their own components.pointerMixin is exported for developers who need to implement or extend pointer-based interaction logic within the multiselect ecosystem.