-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Report] van-time-picker 回显错误 #13084
Comments
这涉及到两个方面的问题:
再说的直白点就是:
这两个问题在下方最小复现代码中均可复现。 |
意思是v-model绑定的变量和组件内部的值实际上不同步是吗?现在的问题是选择开始时间后(时间为00时00分)选择结束时间,由于filter,time-picker会把值变成 function onEndDateChange({ selectedOptions }: any) {
const endDate = selectedOptions.map((option: any) => option.value).join('-')
if (dayjs(endDate).isAfter(dayjs(formModel.value.leaveStartTime))) {
// not working
formModel.value.endTime = ['00', '00']
}
} |
是的,这对应的就是我说的第 1 点,应该是一个 BUG。 |
我试着看了一下相关组件,其中 Picker 组件内部有一个 watch: watch(
() => props.modelValue,
(newValues) => {
if (
!isSameValue(newValues, selectedValues.value) &&
!isSameValue(newValues, lastEmittedModelValue)
) {
selectedValues.value = newValues.slice(0);
lastEmittedModelValue = newValues.slice(0);
}
},
{ deep: true },
); 如果将其中的 牵扯的组件和逻辑有点复杂...要是有空我可能会试着再看看,或者等待其他人来修复这个问题 |
你给的 demo 有些冗余,我这里给一个最小复现: <template>
<div>
<van-date-picker v-model="formModel.date" @change="onChange" />
<van-time-picker
v-model="formModel.time"
:filter="filter"
@confirm="onConfirm"
/>
</div>
</template>
<script setup>
import { ref } from 'vue';
import VanTimePicker from '../../time-picker';
import VanDatePicker from '../../date-picker';
const formModel = ref({});
function onConfirm(data) {
console.log('v-model', formModel.value.time);
console.log('onConfirm', data.selectedValues);
}
function filter(type, options) {
if (
type === 'minute' &&
formModel.value.date?.[1] === '01' &&
formModel.value.date?.[2] === '01'
) {
return options.filter((option) => Number(option.value) > 0);
}
return options;
}
function onChange() {
formModel.value.time = ['00', '00'];
}
</script>
|
@chenjiahan 可以留意一下这个 issue |
重现链接
https://github.com/Alkaidcc/vant-time-picker-issue
Vant 版本
4.9.4
描述一下你遇到的问题。
需求:使用 van-picker-group,van-date-picker,van-time-picker 实现时间选择器,实现所选结束时间大于开始时间。
使用filter做筛选的时候,数据与UI展示不一致
重现步骤
CleanShot.2024-08-26.at.14.00.41.mp4
设备/浏览器
macOS/Chrome
The text was updated successfully, but these errors were encountered: