검색 2글자 이상
This commit is contained in:
parent
fdf439246e
commit
948199c724
@ -1,17 +1,21 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="input-group mb-3 d-flex">
|
<form @submit.prevent="search">
|
||||||
<input
|
<div class="input-group mb-3 d-flex">
|
||||||
type="text"
|
<input
|
||||||
class="form-control"
|
type="text"
|
||||||
placeholder="Search"
|
class="form-control"
|
||||||
v-model="searchQuery"
|
placeholder="Search"
|
||||||
@keyup.enter="search"
|
v-model="searchQuery"
|
||||||
@input="preventLeadingSpace"
|
@input="preventLeadingSpace"
|
||||||
/>
|
/>
|
||||||
<button type="button" class="btn btn-primary" @click="search">
|
<button
|
||||||
<i class="bx bx-search bx-md"></i>
|
type="submit"
|
||||||
</button>
|
class="btn btn-primary"
|
||||||
</div>
|
>
|
||||||
|
<i class="bx bx-search bx-md"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@ -28,15 +32,31 @@ const props = defineProps({
|
|||||||
const emits = defineEmits(["update:data"]);
|
const emits = defineEmits(["update:data"]);
|
||||||
const searchQuery = ref("");
|
const searchQuery = ref("");
|
||||||
|
|
||||||
const search = function () {
|
// 검색 실행 함수 (버튼 클릭 or 엔터 공통)
|
||||||
// Type Number 일때 maxlength 적용 안됨 방지
|
const search = () => {
|
||||||
if (searchQuery.value.length > props.maxlength) {
|
const trimmedQuery = searchQuery.value.trimStart();
|
||||||
searchQuery.value = searchQuery.value.slice(0, props.maxlength);
|
if (trimmedQuery === "") {
|
||||||
|
emits("update:data", "");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (trimmedQuery.length < 2 ) {
|
||||||
|
alert("검색어는 최소 2글자 이상 입력해주세요.");
|
||||||
|
searchQuery.value = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 길이 제한 처리
|
||||||
|
if (trimmedQuery.length > props.maxlength) {
|
||||||
|
searchQuery.value = trimmedQuery.slice(0, props.maxlength);
|
||||||
|
} else {
|
||||||
|
searchQuery.value = trimmedQuery;
|
||||||
|
}
|
||||||
|
|
||||||
emits("update:data", searchQuery.value);
|
emits("update:data", searchQuery.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const preventLeadingSpace = function () {
|
// 좌측 공백 제거
|
||||||
|
const preventLeadingSpace = () => {
|
||||||
searchQuery.value = searchQuery.value.trimStart();
|
searchQuery.value = searchQuery.value.trimStart();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user