검색 필터링 유지
This commit is contained in:
parent
5af68dcf3d
commit
ad3af31e37
@ -1,17 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<form @submit.prevent="search">
|
<form @submit.prevent="search">
|
||||||
<div class="input-group mb-3 d-flex">
|
<div class="input-group mb-3 d-flex">
|
||||||
<input
|
<input type="text" class="form-control" placeholder="Search" v-model="searchQuery" @input="preventLeadingSpace" />
|
||||||
type="text"
|
<button type="submit" class="btn btn-primary">
|
||||||
class="form-control"
|
|
||||||
placeholder="Search"
|
|
||||||
v-model="searchQuery"
|
|
||||||
@input="preventLeadingSpace"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="btn btn-primary"
|
|
||||||
>
|
|
||||||
<i class="bx bx-search bx-md"></i>
|
<i class="bx bx-search bx-md"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -19,7 +10,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from "vue";
|
import { ref, watch } from 'vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
maxlength: {
|
maxlength: {
|
||||||
@ -27,20 +18,30 @@ const props = defineProps({
|
|||||||
default: 30,
|
default: 30,
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
|
initKeyword: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emits = defineEmits(["update:data"]);
|
const emits = defineEmits(['update:data']);
|
||||||
const searchQuery = ref("");
|
const searchQuery = ref('');
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.initKeyword,
|
||||||
|
(newVal, oldVal) => {
|
||||||
|
searchQuery.value = newVal;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// 검색 실행 함수 (버튼 클릭 or 엔터 공통)
|
// 검색 실행 함수 (버튼 클릭 or 엔터 공통)
|
||||||
const search = () => {
|
const search = () => {
|
||||||
const trimmedQuery = searchQuery.value.trimStart();
|
const trimmedQuery = searchQuery.value.trimStart();
|
||||||
if (trimmedQuery === "") {
|
if (trimmedQuery === '') {
|
||||||
emits("update:data", "");
|
emits('update:data', '');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (trimmedQuery.length < 2) {
|
if (trimmedQuery.length < 2) {
|
||||||
alert("검색어는 최소 2글자 이상 입력해주세요.");
|
alert('검색어는 최소 2글자 이상 입력해주세요.');
|
||||||
searchQuery.value = '';
|
searchQuery.value = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -52,7 +53,7 @@ const search = () => {
|
|||||||
searchQuery.value = trimmedQuery;
|
searchQuery.value = trimmedQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
emits("update:data", searchQuery.value);
|
emits('update:data', searchQuery.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 좌측 공백 제거
|
// 좌측 공백 제거
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
<div class="card-header d-flex flex-column">
|
<div class="card-header d-flex flex-column">
|
||||||
<!-- 검색창 -->
|
<!-- 검색창 -->
|
||||||
<div class="mb-3 w-100">
|
<div class="mb-3 w-100">
|
||||||
<search-bar @update:data="search" @keyup.enter="searchOnEnter" class="flex-grow-1" />
|
<search-bar @update:data="search" @keyup.enter="searchOnEnter" :initKeyword="searchText" class="flex-grow-1" />
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex align-items-center" style="gap: 15px">
|
<div class="d-flex align-items-center" style="gap: 15px">
|
||||||
<!-- 리스트 갯수 선택 -->
|
<!-- 리스트 갯수 선택 -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user