1.

<template>
  <el-select v-model="hotel" filterable :filter-method="filterHotel" placeholder="请选择" clearable @clear="hotelClear">
    <el-option v-for="item in options" :key="item.hotelcode" :label="item.hotelname" :value="item.hotelcode">
      <span>{{ item.hotelname }}</span>
      <span>/{{ item.hotelcode }}</span>
    </el-option>
  </el-select>
</template>

2.

hotel:'',
options: [
  {
    hotelname: '选项1',
    hotelcode: 'aaa'
  }, 
  {
    hotelname: '选项2',
    hotelcode: 'bbb'
  }, 
  {
    hotelname: '选项3',
    hotelcode: 'ccc'
  }
],
optionsCopy: []

3.

hotelClear() {
  this.options = this.optionsCopy
},
filterHotel(v) {
  this.options = this.optionsCopy.filter((item) => {
    if (item.hotelname.indexOf(v) != -1 || item.hotelcode.indexOf(v) != -1) { return true}
  })
}

4.

mounted(){
  this.optionsCopy= JSON.parse(JSON.stringify(this.options))
}
作者 铁血 汉子 2021年8月24日
2024/11/21/01:53:08pm 2021/8/24/5:25:31
0 1076