date 타입 관련 추가

This commit is contained in:
yoon 2025-01-21 13:35:42 +09:00
parent 3f96011c2a
commit e66dcad931

View File

@ -11,9 +11,10 @@
class="form-control" class="form-control"
:type="type" :type="type"
@input="updateInput" @input="updateInput"
:value="value" :value="computedValue"
:maxLength="maxlength" :maxLength="maxlength"
:placeholder="title" :placeholder="title"
@blur="$emit('blur')"
/> />
<span class="input-group-text">@ localhost.co.kr</span> <span class="input-group-text">@ localhost.co.kr</span>
</div> </div>
@ -23,21 +24,21 @@
class="form-control" class="form-control"
:type="type" :type="type"
@input="updateInput" @input="updateInput"
:value="value" :value="computedValue"
:maxLength="maxlength" :maxLength="maxlength"
:placeholder="title" :placeholder="title"
@blur="$emit('blur')"
/> />
</div> </div>
<div class="invalid-feedback" :class="isAlert ? 'd-block' : ''">{{ title }} 확인해주세요.</div> <div class="invalid-feedback" :class="isAlert ? 'd-block' : ''">{{ title }} 확인해주세요.</div>
</div> </div>
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref } from 'vue'; import { inject, computed } from 'vue';
const prop = defineProps({ const props = defineProps({
title: { title: {
type: String, type: String,
default: '라벨', default: '라벨',
@ -61,14 +62,14 @@ const prop = defineProps({
value: { value: {
type: String, type: String,
default: '', default: '',
require: false, required: false,
}, },
maxlength: { maxlength: {
type: Number, type: Number,
default: 30, default: 30,
required: false, required: false,
}, },
isAlert : { isAlert: {
type: Boolean, type: Boolean,
default: false, default: false,
required: false, required: false,
@ -78,23 +79,35 @@ const prop = defineProps({
default: false, default: false,
required: false, required: false,
}, },
}); });
const emits = defineEmits(['update:data', 'update:alert']) const emits = defineEmits(['update:data', 'update:alert', 'blur']);
const updateInput = function (event) { // dayjs
//Type Number maxlength const dayjs = inject('dayjs');
if (event.target.value.length > prop.maxlength) {
event.target.value = event.target.value.slice(0, prop.maxlength); // YYYY-MM-DD
const today = dayjs().format('YYYY-MM-DD');
// date ->
const computedValue = computed(() => {
return props.type === 'date' ? props.value || today : props.value;
});
//
const updateInput = event => {
const newValue = event.target.value.slice(0, props.maxlength);
// date
if (props.type === 'date') {
emits('update:data', newValue.replace(/[^0-9-]/g, ''));
} else {
emits('update:data', newValue);
} }
emits('update:data', event.target.value);
// isAlert false // isAlert false
if (event.target.value.trim() !== '') { emits('update:alert', false); } if (newValue.trim() !== '') {
emits('update:alert', false);
}; }
};
</script> </script>
<style>
</style>