Use the filter-method attribute under Select in Element-Plus
basic use
We all know that there is a very useful attribute Element-Plus
in , which can be used by adding it, and it will open a search functionSelect
filterable
Select
Customize the query or get the input value of the drop-down box
When we don't want to use its default search method, or get the value entered in the drop-down box, we can use it to filter-method
achieve it. Note that it will be invalid if it is used after use , filterable
but the value cannot be entered without the drop-down box, so it is still to be used withfilter-method
filterable
filterable
Dropdown box:
<el-select
v-model="form.outTruckId"
placeholder=" "
filterable
clearable
:filter-method="outTruckinput"
@clear="outclear"
v-if="scope.row.action == 'edit'"
>
<el-option
v-for="item in OutTruckOptionList"
:key="item.keyCode"
:label="item.valueCode"
:value="item.keyCode"
/>
</el-select>
function
// 获取下拉框的输入值
function outTruckinput(e) {
// 自定义查询方法
let list = ref();
list.value = OutTruckOptionList.value;
if (e) {
OutTruckOptionList.value = list.value.filter((item) => {
return item.valueCode.indexOf(e) > -1;
});
} else {
//刷新下拉列表
console.log("刷新下拉列表,重新给OutTruckOptionList.value赋值");
}
}