當前使用vue3@3.2.30 + element-plus@2.0.2,封裝的
el-autocomplete
組件使用的vue2的寫法躏精。
一、問題描述
用element 的輸入建議框鹦肿,在點擊清空按鈕后矗烛,如果輸入框已經(jīng)是聚焦狀態(tài),再次輸入內(nèi)容時建議框不顯示。el-autocomplete組件在執(zhí)行清除事件時瞭吃,將activated置為了false碌嘀。當querySearch執(zhí)行成功,activated仍為false歪架,所以下拉框不顯示股冗。
二、解決
1和蚪、給el-autocomplete
添加一個ref
屬性
<el-autocomplete
clearable
class="inline-input"
popper-class="autocomplete-option-list"
highlight-first-item
ref="cautocomplete"
@clear="clear"
...
>
2止状、清空事件中添加this.$refs.cautocomplete.activated = true
clear() {
this.$refs.cautocomplete.activated = true
// or this.$refs.cautocomplete.handleFocus() // 也ok
this.$emit('clear')
}