理解:
如果不采取異步更新,那么每次更新數(shù)據(jù)都會(huì)對(duì)當(dāng)前組件進(jìn)行重新渲染,為了性能考慮,Vue 會(huì)在本輪數(shù)據(jù)更新后,再去異步更新數(shù)據(jù)。
原理:
dep.notify() 通知 watcher 進(jìn)行更新操作
-->subs[i].update() 依次調(diào)用 watcher 的 update
-->queueWatcher 將 watcher 重新放到隊(duì)列中
-->nextTick(flushSchedulerQueue) 異步清空 watcher 隊(duì)列