Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/VanFieldDatePicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const valueDate = ref<string[]>(value.value ?? [])
const valueStr = computed(() => {
return value.value ? value.value.join('-') : ''
})

watch(value, (val) => {
valueDate.value = val ?? []
})
const showPicker = ref(false)
function onConfirm({ selectedValues }: { selectedValues: string[] }) {
value.value = selectedValues
Expand All @@ -51,7 +53,9 @@ function onConfirm({ selectedValues }: { selectedValues: string[] }) {
</script>

<template>
<van-field :model-value="valueStr" v-bind="fieldProps" is-link readonly @click="showPicker = true" />
<slot :open="() => showPicker = true" :value="valueDate" :value-str="valueStr">
<van-field :model-value="valueStr" v-bind="fieldProps" is-link readonly @click="showPicker = true" />
</slot>
<van-popup v-model:show="showPicker" v-bind="popupProps" position="bottom" teleport="body">
<van-date-picker v-model="valueDate" v-bind="datePickerProps" @confirm="onConfirm" @cancel="showPicker = false" />
</van-popup>
Expand Down