element icon indicating copy to clipboard operation
element copied to clipboard

[Select] 可搜索,如何在失去焦点时,选中第一项

Open masterzhang opened this issue 10 years ago • 3 comments

现在做项目遇到一个场景,select可搜索时,如果备选项有[黄金糕,双皮奶],当我输入黄时,列表只有黄金糕这一个选项,希望在失去焦点时,就自动选中黄金糕。

Q: 1、我现在直接在select上监听不到blur事件

masterzhang avatar Nov 21 '16 16:11 masterzhang

写了一个 demo,可以参考一下:http://jsfiddle.net/leopoldthecuber/rco93jgr/1/

Leopoldthecoder avatar Nov 22 '16 04:11 Leopoldthecoder

@Leopoldthecoder 感谢,这样做确实可以,不过当有很多个selected需要进行操作的时候,代码有些冗余。希望可以在组件上封装一个属性,开启这个属性的时候可以获得这个功能。

masterzhang avatar Nov 22 '16 05:11 masterzhang

<tr v-for="(param, index) in params">
          <th width="7.8%">
            <el-select v-model="param.material" filterable
                       ref="material"
                       :filter-method="filterMaterials"
              >
              <el-option
                v-for="(item,index) in materialsSource"
                :label="item.label"
                :value="item">
                <span>{{index+1}}:{{item.label}}</span>
              </el-option>
            </el-select>
          </th>
</tr>

@Leopoldthecoder 开始写的时候发现一个问题,我现在是循环生成的,并不能像你demo写的那样,预先定义定义,并且'params'是变化的,可以增加与删除。那么我该怎么设置呢?

masterzhang avatar Nov 22 '16 06:11 masterzhang