1.0.1 • Published 1 year ago

vue3-basic-autocomplete v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

vue-basic-autocomplete

A Basic Vue.js autocomplete component. (Compatible with Vue.js 3)

Sandbox

Installation

NPM

$ npm install vue3-basic-autocomplete

Register the component

import { createApp } from 'vue'
import App from './App.vue'

import Vue3BasicAutocomplete from 'vue3-basic-autocomplete'

createApp(App)
.use(Vue3BasicAutocomplete)
.mount('#app')

Usage

<vue3-basic-autocomplete v-model="result" :options="items" trackby="name" input-class="form-control" />
// COMPOSITION API
import { toRefs, reactive } from 'vue'
setup () {
    const data = reactive({
        items: [
            {name: 'Josh', id: 1},
            {name: 'David', id: 2},
            {name: 'Angela', id: 3},
            {name: 'Alfred', id: 4},
        ],
        result: '',
    });

    return {
        ...toRefs(data)
    }
}

Available props

PropTypeDefaultDescription
optionsArray (required)Array of items to autocomplete
minlengthNumber1Min. length to start listing. If set to 0, all options will be listed on focus
none-findStringNo matching resultsDefault label when there are no matching results
trackbyStringRequired when you are using an array of objects
placeholderStringPlaceholder
disabledBooleanfalse
list-max-heightString300Max-heigth in px
input-classStringCustom CSS class for the input. Since I am using Bootstrap, I set it as 'form-control'
clear-btnBooleanfalseShows a clear button appended to the input

Events

EventDescription
selectedTriggers when you select any item