We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
flushSchedulerQueue() 函数在遍历执行所有的 watcher 之后,应该要清空当前的 watcher 队列才对的,即 queue.length = 0,完整代码如下:
flushSchedulerQueue()
function flushSchedulerQueue () { let watcher, id; for (index = 0; index < queue.length; index++) { watcher = queue[index] id = watcher.id; has[id] = null; watcher.run(); } waiting = false; queue.length = 0; }
如果不清空队列的话,在以后的 nextTick() 中就会重复执行之前的旧的 watcher ,比如,测试代码中在一秒后再执行 watch1.update() :
(function () { let watch1 = new Watcher(); let watch2 = new Watcher(); watch1.update(); watch1.update(); watch2.update(); setTimeout(() => { watch1.update(); }, 1000) })();
会发现,在一秒之后,只更新了 watcher1, 但是, watcher2 也会执行。
The text was updated successfully, but these errors were encountered:
蛮好 有收获
Sorry, something went wrong.
No branches or pull requests
flushSchedulerQueue()
函数在遍历执行所有的 watcher 之后,应该要清空当前的 watcher 队列才对的,即 queue.length = 0,完整代码如下:如果不清空队列的话,在以后的 nextTick() 中就会重复执行之前的旧的 watcher ,比如,测试代码中在一秒后再执行 watch1.update() :
会发现,在一秒之后,只更新了 watcher1, 但是, watcher2 也会执行。
The text was updated successfully, but these errors were encountered: