Skip to content

Commit eae5f2b

Browse files
author
zhiyang
committed
Autocomplete: fix suggestion data bug
1 parent df7bbe2 commit eae5f2b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/autocomplete/src/autocomplete.vue

+9-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: {
@@ -153,16 +154,21 @@
153154
this.loading = true;
154155
this.fetchSuggestions(queryString, (suggestions) => {
155156
this.loading = false;
157+
if (this.suggestionDisabled) {
158+
return;
159+
}
156160
if (Array.isArray(suggestions)) {
157161
this.suggestions = suggestions;
158162
} else {
159-
console.error('autocomplete suggestions must be an array');
163+
console.error('[Element Warn][Autocomplete]autocomplete suggestions must be an array');
160164
}
161165
});
162166
},
163167
handleChange(value) {
164168
this.$emit('input', value);
169+
this.suggestionDisabled = false;
165170
if (!this.triggerOnFocus && !value) {
171+
this.suggestionDisabled = true;
166172
this.suggestions = [];
167173
return;
168174
}
@@ -228,9 +234,7 @@
228234
}
229235
},
230236
mounted() {
231-
this.debouncedGetData = debounce(this.debounce, (val) => {
232-
this.getData(val);
233-
});
237+
this.debouncedGetData = debounce(this.debounce, this.getData);
234238
this.$on('item-click', item => {
235239
this.select(item);
236240
});

0 commit comments

Comments
 (0)