<script setup lang="ts">
import { computed, ref } from 'vue';
interface Option {
label: string;
value: unknown;
}
// Данный синтаксис доступен в Vue 3.5 и выше
const {
options,
optionLabel = 'label',
optionValue = 'value',
} = defineProps<{
options: Option[];
optionLabel?: string;
optionValue?: string;
}>();
const filter = ref('');
const filteredOptions = computed(() => {
const tmp = filter.value.trim().toLowerCase(); // trim чтоб убрать пробелы
if (tmp === '') return options;
return options.filter(option =>
option[optionLabel].toLowerCase().includes(tmp),
);
});
</script>