Created
August 10, 2017 01:01
-
-
Save dohomi/66aab733038ff1b4d1d0c218160a0412 to your computer and use it in GitHub Desktop.
simple autocomplete with debounce async search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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