From 2445a7bc0011af11b97dbe986e01d0e152f32da5 Mon Sep 17 00:00:00 2001 From: hetech Date: Thu, 24 May 2018 19:07:19 +0800 Subject: [PATCH] Autocomplete: fix suggestions data bug (#11323) --- packages/autocomplete/src/autocomplete.vue | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/autocomplete/src/autocomplete.vue b/packages/autocomplete/src/autocomplete.vue index 58d14830b..8f6b39849 100644 --- a/packages/autocomplete/src/autocomplete.vue +++ b/packages/autocomplete/src/autocomplete.vue @@ -122,7 +122,8 @@ activated: false, suggestions: [], loading: false, - highlightedIndex: -1 + highlightedIndex: -1, + suggestionDisabled: false }; }, computed: { @@ -150,19 +151,27 @@ }; }, getData(queryString) { + if (this.suggestionDisabled) { + return; + } this.loading = true; this.fetchSuggestions(queryString, (suggestions) => { this.loading = false; + if (this.suggestionDisabled) { + return; + } if (Array.isArray(suggestions)) { this.suggestions = suggestions; } else { - console.error('autocomplete suggestions must be an array'); + console.error('[Element Error][Autocomplete]autocomplete suggestions must be an array'); } }); }, handleChange(value) { this.$emit('input', value); + this.suggestionDisabled = false; if (!this.triggerOnFocus && !value) { + this.suggestionDisabled = true; this.suggestions = []; return; } @@ -228,9 +237,7 @@ } }, mounted() { - this.debouncedGetData = debounce(this.debounce, (val) => { - this.getData(val); - }); + this.debouncedGetData = debounce(this.debounce, this.getData); this.$on('item-click', item => { this.select(item); });