el-autocomplete select事件传递多个参数

转自: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 参数了。

 

原文地址:https://www.cnblogs.com/zkx4213/p/15185346.html