Nuxt Vue Multiselect Module
This Nuxt.js module integrates the `vue-multiselect` component into Nuxt applications, simplifying its setup and usage. It handles the automatic global registration of the `Multiselect` component, allowing developers to use `<multiselect>` directly in their Vue templates without manual imports. `vue-multiselect` itself is a popular component for single/multiple selection, tagging, and asynchronous search capabilities, offering extensive customization through props and slots. This specific Nuxt wrapper, currently at version 1.0.4, shows its last significant activity around 2020. Given its reliance on `vue-multiselect` (which primarily supports Vue 2) and the lack of recent updates, `nuxt-vue-multiselect` is not compatible with Nuxt 3 or Vue 3 projects and should be considered abandoned for modern Nuxt development, best suited for existing Nuxt 2 applications.
Common errors
-
[Vue warn]: Unknown custom element: <multiselect> - did you register the component correctly?
cause The `nuxt-vue-multiselect` module was not correctly added to `nuxt.config.js` or there's an issue with Nuxt's component auto-registration.fixEnsure 'nuxt-vue-multiselect' is present in the `modules` array within your `nuxt.config.js` file and restart your Nuxt development server. -
TypeError: Cannot read properties of undefined (reading 'data') (in <Multiselect>)
cause This typically occurs if the `v-model` binding for `<multiselect>` is not initialized with an appropriate value (e.g., `null` for single select, `[]` for multiple select) or if the `options` prop is `undefined` or not an array.fixInitialize your `v-model` data property to `null` or `[]` (based on `multiple` prop) and ensure `options` is always an array of objects. -
Cannot find module 'vue-multiselect/dist/vue-multiselect.min.css'
cause The CSS file for `vue-multiselect` is not being found or imported correctly by your build process.fixAdd `'vue-multiselect/dist/vue-multiselect.min.css'` to the `css` array in `nuxt.config.js`, or manually `@import` it in a global stylesheet.
Warnings
- breaking This module is built for Nuxt 2 (Vue 2) and is not compatible with Nuxt 3 (Vue 3) projects. Attempting to use it in a Nuxt 3 application will lead to runtime errors or build failures.
- gotcha The `vue-multiselect` CSS (`vue-multiselect/dist/vue-multiselect.min.css`) may not be automatically included by the Nuxt module in all configurations, leading to unstyled components. This is a common oversight.
- deprecated The `nuxt-vue-multiselect` module is not actively maintained, with its last commit activity dating back to 2020. This means it may not receive updates for security vulnerabilities, bug fixes, or compatibility with newer Node.js/npm versions.
- breaking The underlying `vue-multiselect` library itself is primarily designed for Vue 2 and is also not actively maintained for Vue 3. This compounds the abandonment status of the Nuxt wrapper.
Install
-
npm install nuxt-vue-multiselect -
yarn add nuxt-vue-multiselect -
pnpm add nuxt-vue-multiselect
Imports
- Multiselect
import { Multiselect } from 'nuxt-vue-multiselect'<!-- Use directly in template: <multiselect ... /> -->
- default
import NuxtVueMultiselect from 'nuxt-vue-multiselect'
// nuxt.config.js export default { modules: ['nuxt-vue-multiselect'] } - Multiselect (type)
import type { Multiselect } from 'nuxt-vue-multiselect'import type { Multiselect } from 'vue-multiselect'
Quickstart
/* nuxt.config.js */
export default {
modules: [
'nuxt-vue-multiselect'
],
// It's often necessary to manually include the CSS for vue-multiselect.
// You can do this globally in nuxt.config.js or directly in a component.
css: [
'vue-multiselect/dist/vue-multiselect.min.css'
],
// If targeting older browsers, you might need to transpile vue-multiselect
build: {
transpile: ['vue-multiselect']
}
}
/* pages/index.vue (or any other Vue component) */
<template>
<div>
<h1>Select Your Favorite Frameworks</h1>
<label for="framework-select">Choose some frameworks:</label>
<multiselect
id="framework-select"
v-model="selectedFrameworks"
:options="availableFrameworks"
:multiple="true"
:close-on-select="false"
:clear-on-select="false"
:searchable="true"
placeholder="Pick frameworks"
label="name"
track-by="name"
></multiselect>
<p>Currently selected: {{ selectedFrameworks.map(f => f.name).join(', ') || 'None' }}</p>
</div>
</template>
<script lang="ts">
import Vue from 'vue'
interface FrameworkOption {
name: string;
code: string;
}
export default Vue.extend({
name: 'FrameworkSelector',
data() {
return {
selectedFrameworks: [] as FrameworkOption[],
availableFrameworks: [
{ name: 'Vue.js', code: 'VUE' },
{ name: 'Nuxt.js', code: 'NUXT' },
{ name: 'React', code: 'REACT' },
{ name: 'Angular', code: 'ANGULAR' },
{ name: 'Svelte', code: 'SVELTE' },
{ name: 'Solid', code: 'SOLID' }
]
}
},
})
</script>