Skip to content

Commit 80bec51

Browse files
author
zhiyang
committed
Autocomplete: fix suggestions data bug
1 parent df7bbe2 commit 80bec51

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/autocomplete/src/autocomplete.vue

+12-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
activated: false,
123123
suggestions: [],
124124
loading: false,
125-
highlightedIndex: -1
125+
highlightedIndex: -1,
126+
suggestionDisabled: false
126127
};
127128
},
128129
computed: {
@@ -150,19 +151,27 @@
150151
};
151152
},
152153
getData(queryString) {
154+
if (this.suggestionDisabled) {
155+
return;
156+
}
153157
this.loading = true;
154158
this.fetchSuggestions(queryString, (suggestions) => {
155159
this.loading = false;
160+
if (this.suggestionDisabled) {
161+
return;
162+
}
156163
if (Array.isArray(suggestions)) {
157164
this.suggestions = suggestions;
158165
} else {
159-
console.error('autocomplete suggestions must be an array');
166+
console.error('[Element Warn][Autocomplete]autocomplete suggestions must be an array');
160167
}
161168
});
162169
},
163170
handleChange(value) {
164171
this.$emit('input', value);
172+
this.suggestionDisabled = false;
165173
if (!this.triggerOnFocus && !value) {
174+
this.suggestionDisabled = true;
166175
this.suggestions = [];
167176
return;
168177
}
@@ -228,9 +237,7 @@
228237
}
229238
},
230239
mounted() {
231-
this.debouncedGetData = debounce(this.debounce, (val) => {
232-
this.getData(val);
233-
});
240+
this.debouncedGetData = debounce(this.debounce, this.getData);
234241
this.$on('item-click', item => {
235242
this.select(item);
236243
});

0 commit comments

Comments
 (0)