fix(time-picker): fix time-picker components bug (#1461)

This commit is contained in:
李天佑 2024-03-05 17:41:37 +08:00 committed by GitHub
parent 28a67f7507
commit e48aacede9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -48,6 +48,9 @@ export const decrease =
export const modifyDateField =
({ emit, props, state }) =>
(type, value) => {
if (state[type] === value) {
return
}
switch (type) {
case 'hours':
emit('change', modifyTime(props.date, value, state.minutes, state.seconds))

View File

@ -78,7 +78,7 @@ const initState = ({ reactive, computed, props, api }) => {
return state
}
export const renderless = (props, { computed, onMounted, reactive, watch }, { emit, vm, constants }) => {
export const renderless = (props, { computed, onMounted, reactive, watch, nextTick }, { emit, vm, constants }) => {
const api = {}
const state = initState({ reactive, computed, props, api })
@ -108,13 +108,14 @@ export const renderless = (props, { computed, onMounted, reactive, watch }, { em
})
watch(
() => props.date.getTime(),
() => props.date,
() => {
const timeType = ['hours', 'minutes', 'seconds']
timeType.forEach((type) => {
api.modifyDateField(type, Math.round(state[type] / state.step[type]) * state.step[type])
})
nextTick(api.adjustSpinners)
},
{ immediate: true }
)