转自:https://yuyuye958.github.io/2019/03/10/el-autocomplete/

问题

<el-autocomplete
  v-model="state"
  :fetch-suggestions="querySearchAsync"
  placeholder="请输入内容"
  @select="handleSelect"
></el-autocomplete>

这是 Element UI 官方文档中 el-autocomplete 的示例,而这里的 handleSelect 默认绑定的参数是你选中的那条数据。

但是如果你需求用 v-for 生成多个组件,要把 index 给传进这个方法,你可能会这样做:

@select="handleSelect(item, index)"

经试验这是行不通的,那么该如何做呢?

方法

<el-autocomplete
  v-model="state"
  :fetch-suggestions="querySearchAsync"
  placeholder="请输入内容"
  @select="((item) => {handleSelect(item, index)})"
></el-autocomplete>

这样你就能在 handleSelect 方法中拿到 index 参数了。

 

相关文章:

  • 2021-10-19
  • 2021-09-17
  • 2021-07-04
猜你喜欢
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-01-31
  • 2022-01-22
  • 2021-06-02
  • 2022-01-18
相关资源
相似解决方案