WHY v-model.lazy won't update the focus input dom/ 双向绑定的input元素,回车触发watch回调中修改的值不会更新到input中 #8238
-
Vue versionvue3.3 Link to minimal reproductionhttps://codepen.io/xflyyxfl-the-typescripter/pen/poxpwKK Steps to reproduce1、把输入框里面的值修改为一个超出1-10范围的数/Edit to a new number out of range 1-10 What is expected?v-model.lazy绑定的input即使在焦点状态也要更新其值/v-model.lazy must update the focus dom What is actually happening?v-model.lazy绑定的input即使在焦点状态时,它的值与绑定的响应式变量不同/focus inputdom won't update System InfoChrome V111.0.5563.111
edge the same Any additional comments?No response |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 2 replies
-
看你的例子,你使用了v-model.lazy, 只有在按回车或者输入框失去聚焦后才会触发watch的 |
Beta Was this translation helpful? Give feedback.
-
是的,所以呢,是这样不合理吗 |
Beta Was this translation helpful? Give feedback.
-
你想实时监听就别用lazy呗 |
Beta Was this translation helpful? Give feedback.
-
我是在正式项目使用中遇到的问题,不使用lazy可能导致逻辑问题。 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
也不是不可以,但是这样肯定是比直接任何地方一个v-model绑定要麻烦。 |
Beta Was this translation helpful? Give feedback.
-
我在官方源码里面已经找到原因了,但是对于官方尤大这样的选择仍然不太清楚,可能是基于某些需求下的考量: When an input is changing with lazy-bound responses, if the user happens to be editing the input, the changed data will not update the value to the input box so as not to affect the user's editing The benefit is that in the case above, the user input experience is the primary one. The downside is that problems can occur when developers want to actively update. |
Beta Was this translation helpful? Give feedback.
-
官方是崩坏了吗?没有任何表态直接把issue变成讨论? Just move it from issue to disscusion by Vue team without any comment, shit! |
Beta Was this translation helpful? Give feedback.
我在官方源码里面已经找到原因了,但是对于官方尤大这样的选择仍然不太清楚,可能是基于某些需求下的考量:
当某个input用lazy绑定的响应式在变化时,用户如果刚好也在编辑这个输入,那么变化的数据为了不影响用户的编辑,不会主动更新这个值到输入框;
好处是上面的这种情况,以用户输入体验为主。坏处就是当开发者想主动更新时就会发生问题。
示例代码仍然在https://codepen.io/xflyyxfl-the-typescripter/pen/poxpwKK?editors=1010
/////
I have found the reason in the official source code, but it is still not clear for the official/You such choice, may be based on some needs under consideration:
When an input is changing with lazy-bound responses, if the user happens to be editing the input, the changed data will not update the value to the input box so as not to affect the user's editing
The benefit is that in the case above, the user input experience is the primary one. The d…