watch对响应数据变化的触发时机在多个vue版本中表现不一致 #7123
Unanswered
Liu-Wenbin
asked this question in
Help/Questions
Replies: 2 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
3 replies
-
最近的几个版本中确实改过 这是其中一个 demo 。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
场景:父组件定义msg为ref,msg1是computed并且依赖于msg,watch监听msg和msg1的变化。将msg和msg1通过props传入子组件,在子组件中同样watch监听msg和msg1的变化,然后修改msg的值,查看变化顺序。
在[email protected]中,执行顺序是:
1.计算属性msg1的getter
2.计算属性msg1的watcher
3.msg的watcher
4.子组件的msg1的watcher
5.子组件的msg的watcher
而在[email protected]中,执行顺序是:(在子组件中,msg和msg1的watcher执行顺序颠倒了)
1.计算属性msg1的getter
2.计算属性msg1的watcher
3msg的watcher
4.子组件的msg的watcher
5.子组件的msg1的watcher
我又试了vue2中,执行顺序又不一样:
1.msg的watcher
2.计算属性msg1的getter
3.计算属性msg1的watcher
4.子组件的msg的watcher
5.子组件的msg1的watcher
为什么各个版本的vue,它们的触发顺序这样不一致,是故意这么设计的还是设计时就没有考虑这个呢?
Beta Was this translation helpful? Give feedback.
All reactions