fix(TimePicker): fix the 'modelValue' watch defect#13095
fix(TimePicker): fix the 'modelValue' watch defect#13095pany-ang wants to merge 1 commit intoyouzan:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13095 +/- ##
==========================================
+ Coverage 89.66% 89.68% +0.01%
==========================================
Files 257 257
Lines 6987 6988 +1
Branches 1724 1725 +1
==========================================
+ Hits 6265 6267 +2
+ Misses 382 380 -2
- Partials 340 341 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
同理,逻辑相似的 |
|
可以补充一下单元测试 |
|
该 PR 不太好用单测来测试,暂时没找到通过单测触发新增逻辑的办法。参考 issue 中提到的手动复现办法,也是需要两个组件 + 人工按照一定逻辑操作 4 次界面。 如果 CR 能通过,也许这里并不需要单测也行。 |
| const _newValues = formatValueRange(newValues, columns.value); | ||
| if ( | ||
| !isSameValue(_newValues, currentValues.value) || | ||
| !isSameValue(_newValues, newValues) |
There was a problem hiding this comment.
这里为什么需要加这个判断呢,从 issue 中没有看到解释
There was a problem hiding this comment.
- v-model 修改为 ['00', '00'] 时,此时 UI 上没有 ['00', '00'] 选项,UI 被迫选中最接近的一个值,但是 v-model 没有同步更新为该值,依旧是 ['00', '00'](UI 变了,但 v-model 没变)(可能是一个 BUG)
对应的是 issue 中这段话
There was a problem hiding this comment.
对于新加的这个 if 判断,似乎只有在 currentValues.value 和 _newValues 相等的时候会触发,那下面的 currentValues.value = _newValues; 赋值有什么意义呢?
There was a problem hiding this comment.
该赋值为了触发这段侦听器:
watch(currentValues, (newValues) => {
if (!isSameValue(newValues, props.modelValue)) {
emit('update:modelValue', newValues);
}
});
目的是让内部的 currentValues 同步到外部的 v-model 绑定的变量
解决该 issue 中提到的第 2 个问题: #13084