akkoma-fe/src/components/user_autosuggest/user_autosuggest.js

35 lines
711 B
JavaScript
Raw Normal View History

2019-04-02 10:12:31 +00:00
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
import userSearchApi from '../../services/new_api/user_search.js'
const debounceMilliseconds = 500
2019-04-02 10:12:31 +00:00
export default {
components: {
BasicUserCard
},
data () {
return {
query: '',
2019-04-02 10:12:31 +00:00
results: [],
timeout: null
}
},
watch: {
query (val) {
this.fetchResults(val)
2019-04-02 10:12:31 +00:00
}
},
methods: {
fetchResults (query) {
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
this.results = []
if (query) {
userSearchApi.search({query, store: this.$store})
.then((data) => { this.results = data })
}
}, debounceMilliseconds)
2019-04-02 10:12:31 +00:00
}
}
}