refactor: emit search
This commit is contained in:
parent
8d32765cce
commit
7510928e66
1 changed files with 11 additions and 1 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { watch } from 'vue';
|
||||||
|
|
||||||
const search = defineModel<string>('search');
|
const search = defineModel<string>('search');
|
||||||
const selectedItem = defineModel<unknown[]>('selectedItem', { default: [] });
|
const selectedItem = defineModel<unknown[]>('selectedItem', { default: [] });
|
||||||
|
|
||||||
|
|
@ -23,8 +25,16 @@ const props = withDefaults(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'search', v: string): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
defineExpose({ select, assignSelect });
|
defineExpose({ select, assignSelect });
|
||||||
|
|
||||||
|
watch(search, () => {
|
||||||
|
emit('search', search.value || '');
|
||||||
|
});
|
||||||
|
|
||||||
function select(item?: unknown, all?: boolean) {
|
function select(item?: unknown, all?: boolean) {
|
||||||
if (all) {
|
if (all) {
|
||||||
if (props.items.every((item) => selectedItem.value.includes(item))) {
|
if (props.items.every((item) => selectedItem.value.includes(item))) {
|
||||||
|
|
@ -76,7 +86,7 @@ function assignSelect(to: unknown[], from: unknown[]) {
|
||||||
class="q-ml-auto"
|
class="q-ml-auto"
|
||||||
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
|
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
|
||||||
v-model="search"
|
v-model="search"
|
||||||
debounce="200"
|
debounce="300"
|
||||||
>
|
>
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<q-icon name="mdi-magnify" />
|
<q-icon name="mdi-magnify" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue