diff options
| author | taehoon <th.dev91@gmail.com> | 2019-04-02 12:31:45 -0400 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-04-14 23:44:49 -0400 |
| commit | 94e67ff11894c13bf34f1b31802a1497caa03897 (patch) | |
| tree | f5ed454fbcdf534f6df5cd36cf51f9c642caaf65 /src/components/user_autosuggest/user_autosuggest.js | |
| parent | da5844205c5e2ead4da42f89f1f9586683af693e (diff) | |
rewrite USerAutoSuggest without any dependency
Diffstat (limited to 'src/components/user_autosuggest/user_autosuggest.js')
| -rw-r--r-- | src/components/user_autosuggest/user_autosuggest.js | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js index 6612c2f3..eff6ef75 100644 --- a/src/components/user_autosuggest/user_autosuggest.js +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -1,41 +1,34 @@ -import { VueAutosuggest } from 'vue-autosuggest' import BasicUserCard from '../basic_user_card/basic_user_card.vue' import userSearchApi from '../../services/new_api/user_search.js' +const debounceMilliseconds = 500 + export default { components: { - VueAutosuggest, BasicUserCard }, data () { return { + query: '', results: [], - timeout: null, - selected: null, - debounceMilliseconds: 500, - inputProps: { - id: 'autosuggest__input', - onInputChange: this.fetchResults, - placeholder: 'Search...', - class: 'form-control' - }, - suggestions: [] + timeout: null + } + }, + watch: { + query (val) { + this.fetchResults(val) } }, methods: { fetchResults (query) { clearTimeout(this.timeout) this.timeout = setTimeout(() => { - userSearchApi.search({query, store: this.$store}) - .then((data) => { this.suggestions = [{ data }] }) - }, this.debounceMilliseconds) - }, - clickHandler (item) { - return false - }, - clickUserHandler () { - console.log('clickUserHandler') - return false + this.results = [] + if (query) { + userSearchApi.search({query, store: this.$store}) + .then((data) => { this.results = data }) + } + }, debounceMilliseconds) } } } |
