修复了默认时间的组件有显示但是提交值是空的问题
This commit is contained in:
@ -13,10 +13,10 @@
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import dayjs, {Dayjs} from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
import {ref, watch, computed} from 'vue';
|
import { ref, watch, computed } from 'vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
value: [dayjs, String, Object],
|
value: [dayjs, String, Object],
|
||||||
size: String,
|
size: String,
|
||||||
placeholder: String,
|
placeholder: String,
|
||||||
@ -27,11 +27,11 @@ const props = defineProps({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const modelValue = ref<Dayjs>();
|
const modelValue = ref<Dayjs>();
|
||||||
const emit = defineEmits(['update:value']);
|
const emit = defineEmits(['update:value']);
|
||||||
|
|
||||||
const picker = computed(() => {
|
const picker = computed(() => {
|
||||||
let time = 'date';
|
let time = 'date';
|
||||||
switch (props.format) {
|
switch (props.format) {
|
||||||
case 'YYYY-MM':
|
case 'YYYY-MM':
|
||||||
@ -42,17 +42,17 @@ const picker = computed(() => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return time;
|
return time;
|
||||||
});
|
});
|
||||||
watch(
|
watch(
|
||||||
() => props.value,
|
() => props.value,
|
||||||
(val) => {
|
(val) => {
|
||||||
modelValue.value = dayjs(val || undefined);
|
modelValue.value = val ? dayjs(val || undefined) : '';
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
immediate: true,
|
immediate: true
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
const handleChange = (time) => {
|
const handleChange = (time) => {
|
||||||
emit('update:value', time);
|
emit('update:value', time);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user