美文网首页
Vue源码解析-Vue异步更新过程

Vue源码解析-Vue异步更新过程

作者: v雪狐v | 来源:发表于2020-07-10 23:30 被阅读0次
  • src/core/observer/dep.js
    • notify() //执行了对所有watcher对遍历
      通过调用:
  • src/core/observer/watcher.js
    • update() 方法
      如果是异步 执行:
  • src/core /observer/watcher.js
    • queueWatcher()
      1. 获取所有watcher唯一id
      2. 判断watcher是否入队,去重。
      • 如果watcher为同步直接执行flushSchedulerQueue();否则nextTick(flushSchedulerQueue)
  • src/core/util/next-tick.js
    • nextTick() 内调用了
      timerFunc() 来判断当前环境的异步方法
      异步选择顺序为: Promise、MutationObserver、setImmediate 、setTimeout
      flushCallbacks() //存储用户传入回调
  • src/core /observer/scheduler.js
    • flushSchedulerQueue() 执行了队列排序,遍历队列中的watcher实例,并调用run()方法

相关文章

网友评论

      本文标题:Vue源码解析-Vue异步更新过程

      本文链接:https://www.haomeiwen.com/subject/sqwvcktx.html