修复 search-method 自定义搜索逻辑不生效

This commit is contained in:
就眠儀式 2022-11-29 21:48:34 +08:00
parent 0c0d4d19f3
commit ad047574b4
2 changed files with 12 additions and 7 deletions

View File

@ -60,14 +60,13 @@ const selected = computed(() => {
} }
}); });
// , search-method const first = ref(true);
const isFirst = ref(true);
const display = computed(() => { const display = computed(() => {
if (searchMethod && !isFirst.value) { if (searchMethod && !first.value) {
isFirst.value = false;
return searchMethod(searchValue.value, props); return searchMethod(searchValue.value, props);
} }
first.value = false;
return ( return (
props.keyword?.toString().indexOf(searchValue.value) > -1 || props.keyword?.toString().indexOf(searchValue.value) > -1 ||
props.label?.toString().indexOf(searchValue.value) > -1 props.label?.toString().indexOf(searchValue.value) > -1

View File

@ -122,7 +122,7 @@ export default {
<lay-select-option value="2" label="编码"></lay-select-option> <lay-select-option value="2" label="编码"></lay-select-option>
<lay-select-option value="3" label="运动"></lay-select-option> <lay-select-option value="3" label="运动"></lay-select-option>
</lay-select> </lay-select>
<lay-select v-model="value4" :show-search="true" :multiple="true"> <lay-select v-model="value4" :show-search="true" :multiple="true" :search-method="searchMethod">
<lay-select-option value="1" label="学习"></lay-select-option> <lay-select-option value="1" label="学习"></lay-select-option>
<lay-select-option value="2" label="编码"></lay-select-option> <lay-select-option value="2" label="编码"></lay-select-option>
<lay-select-option value="3" label="运动"></lay-select-option> <lay-select-option value="3" label="运动"></lay-select-option>
@ -139,9 +139,14 @@ export default {
const value3 = ref('1') const value3 = ref('1')
const value4 = ref(['1']) const value4 = ref(['1'])
const searchMethod = (text, props) => {
return props.label.indexOf(text) != -1;
}
return { return {
value3, value3,
value4 value4,
searchMethod
} }
} }
} }
@ -207,9 +212,10 @@ export default {
const value3 = ref('1') const value3 = ref('1')
const value4 = ref(['1']) const value4 = ref(['1'])
return { return {
value3, value3,
value4 value4,
} }
} }
} }