首页 > 解决方案 > 在元素(Vue)自动完成中选择后保持下拉

问题描述

我正在为我的项目使用 Element。当我使用自动完成输入时,我希望在选择元素时保持下拉列表完整,并且仅在模糊时隐藏它。谁能帮我? https://element.eleme.io/#/en-US/component/input

标签: vue.jsautocompleteelement

解决方案


如果不分叉库或编写自己的组件,就没有合理的方法可以做到这一点。

Here is the code in elements source that always closes the autocomplete when a choice is selected:

select(item) {
  this.$emit('input', item[this.valueKey]);
  this.$emit('select', item);
  this.$nextTick(_ => {
    this.suggestions = []; // This will always close the suggestions tooltip
    this.highlightedIndex = -1;
  });
}

来源

如果您不想分叉整个库并且您正在单独导入组件,您可以 1. 导入el-autocomplete组件,2. 覆盖select方法,3. 注册修改后的组件。


推荐阅读