Skip to content

Instantly share code, notes, and snippets.

@dohomi
Created August 10, 2017 01:01
Show Gist options
  • Save dohomi/66aab733038ff1b4d1d0c218160a0412 to your computer and use it in GitHub Desktop.
Save dohomi/66aab733038ff1b4d1d0c218160a0412 to your computer and use it in GitHub Desktop.
simple autocomplete with debounce async search
<template>
<v-select
v-model="state"
label="Select"
:items="states"
@input.native="loadStates"
autocomplete
></v-select>
</template>
<script>
import debounce from 'debounce'
export default {
data () {
return {
state: null,
states: []
}
},
methods: {
loadStates: debounce((event) => {
if (event.target.value.length > 2) {
axios.get(`/api/states?q=${event.target.value}`).then(({ data }) => {
this.states = data
})
}
}, 200)
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment