The Quasar Autocomplete component binds to the parent textfield (eg. QInput, QSearch, QChipsInput) and offers suggestions to the user, while the user is typing. The suggestions offered to the user are based on either a static list of results or on an asynchronous function call (eg. containing an Ajax request).
Installation
Edit /quasar.conf.js:
framework: { components: ['QAutocomplete'] }
Basic Usage
As long as this component is rendered by Vue, it will capture all Ajax calls.
<script> import countries from'countries.json' // See above for the data format for the array of objects with required and optional data exportdefault { data () { return { terms: '', countries } } } </script>
Custom Filter
To perform custom filtering like fuzzy search, provide an optional function with following signature:
<template> <q-searchv-model="terms"> <!-- Provide custom filter function --> <q-autocomplete :filter="myFilter" @search="search" @selected="selected" /> </q-search> </template>
If you’d like to call up data from the server, you may also do so with the following usage of search() method.
<template> <q-searchv-model="terms"placeholder="Start typing a country name"> <q-autocomplete @search="search" @selected="selected" /> </q-search> </template>
<script> exportdefault { ... methods: { search (terms, done) { // make an AJAX call // then call done(Array results) // DO NOT forget to call done! When no results or an error occurred, // just call with empty array as param. Example: done([]) } }, ... } </script>