mirror of https://github.com/ElemeFE/element
Autocomplete: fix suggestions data bug (#11323)
parent
f18bbeb473
commit
2445a7bc00
|
@ -122,7 +122,8 @@
|
||||||
activated: false,
|
activated: false,
|
||||||
suggestions: [],
|
suggestions: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
highlightedIndex: -1
|
highlightedIndex: -1,
|
||||||
|
suggestionDisabled: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -150,19 +151,27 @@
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getData(queryString) {
|
getData(queryString) {
|
||||||
|
if (this.suggestionDisabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.fetchSuggestions(queryString, (suggestions) => {
|
this.fetchSuggestions(queryString, (suggestions) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
if (this.suggestionDisabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Array.isArray(suggestions)) {
|
if (Array.isArray(suggestions)) {
|
||||||
this.suggestions = suggestions;
|
this.suggestions = suggestions;
|
||||||
} else {
|
} else {
|
||||||
console.error('autocomplete suggestions must be an array');
|
console.error('[Element Error][Autocomplete]autocomplete suggestions must be an array');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleChange(value) {
|
handleChange(value) {
|
||||||
this.$emit('input', value);
|
this.$emit('input', value);
|
||||||
|
this.suggestionDisabled = false;
|
||||||
if (!this.triggerOnFocus && !value) {
|
if (!this.triggerOnFocus && !value) {
|
||||||
|
this.suggestionDisabled = true;
|
||||||
this.suggestions = [];
|
this.suggestions = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -228,9 +237,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.debouncedGetData = debounce(this.debounce, (val) => {
|
this.debouncedGetData = debounce(this.debounce, this.getData);
|
||||||
this.getData(val);
|
|
||||||
});
|
|
||||||
this.$on('item-click', item => {
|
this.$on('item-click', item => {
|
||||||
this.select(item);
|
this.select(item);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue