Skip to content
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

vue nextTick的一些解释 #49

Open
shinena opened this issue Apr 25, 2019 · 1 comment
Open

vue nextTick的一些解释 #49

shinena opened this issue Apr 25, 2019 · 1 comment

Comments

@shinena
Copy link
Owner

shinena commented Apr 25, 2019

更新Dom函数和nextTick的回调函数都在microtask队列里,而microtask队列只会在所有同步任务都执行完后才会执行,这样就保证了,Dom更新和nextTick的回调函数一定在数据更新后,而callbacks数组里的顺序保证了nextTick的回调函数一定在Dom更新后(特别提醒:Dom更新是同步的,ui渲染才是异步的)。

@shinena
Copy link
Owner Author

shinena commented Apr 25, 2019

用MutationObserver只是因为他的microtask特性,在源码中我们也看到了假如不支持MutationObserver,还有setImmediate等选择,最后实在不行只能用setTimeOut(setTimeOut只有Macrotasks特性,没办法才用他 )。其实假如有更好的选择,MutationObserver也会被换掉,实际上在Vue2.5.x以后,MutationObserver也确实因为某些兼容问题被去掉了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant