修复了默认时间的组件有显示但是提交值是空的问题

This commit is contained in:
Je
2025-02-17 17:11:51 +08:00
parent 4ef45f933e
commit 40fbce7e7c

View File

@ -13,10 +13,10 @@
/>
</template>
<script lang="ts" setup>
import dayjs, {Dayjs} from 'dayjs';
import {ref, watch, computed} from 'vue';
import dayjs, { Dayjs } from 'dayjs';
import { ref, watch, computed } from 'vue';
const props = defineProps({
const props = defineProps({
value: [dayjs, String, Object],
size: String,
placeholder: String,
@ -27,11 +27,11 @@ const props = defineProps({
type: Boolean,
default: false
}
});
const modelValue = ref<Dayjs>();
const emit = defineEmits(['update:value']);
});
const modelValue = ref<Dayjs>();
const emit = defineEmits(['update:value']);
const picker = computed(() => {
const picker = computed(() => {
let time = 'date';
switch (props.format) {
case 'YYYY-MM':
@ -42,17 +42,17 @@ const picker = computed(() => {
break;
}
return time;
});
watch(
});
watch(
() => props.value,
(val) => {
modelValue.value = dayjs(val || undefined);
modelValue.value = val ? dayjs(val || undefined) : '';
},
{
immediate: true,
},
);
const handleChange = (time) => {
immediate: true
}
);
const handleChange = (time) => {
emit('update:value', time);
};
};
</script>