vue异步更新流程
2024-02-21 11:43:39 0 举报
AI智能生成
VUE VUEX VUE异步更新
作者其他创作
大纲/内容
<font color="#c41230">core/observer/index.js defineReactive()</font> obj的key响应式拦截(也就是数据变更引起的操作)
<font color="#c41230">src/core/observer/dep.js dep.notify() </font>遍历内部所有的watcher
<font color="#c41230">src/core/observer/watcher.js</font> watcher.update() 执行入队操作<br><br>
<font color="#c41230">src/core/observer/watcher.js</font> queueWatcher(this) 把watcher加入队列中,然后执行nextTick()方法<br><br>
<font color="#c41230">src/core/util/next-tick.js </font> nextTick(flushSchedulerQueue)<br><font color="#c41230">如果直接调用$nextTick(callback), 就不会加入到flushSchedulerQueue,<br>那就不会执行 updateComponent方法了</font>
<font color="#c41230">src/core/util/next-tick.js </font><font color="#381e11">timeFunc() </font><br>将flushCallbacks放进微任务队列中,并执行flushcallbacks方法,<br>也就是 flushScheduleQueue()
flushSchedulerQueues()<br>主要做的操作就是watcher.run()<br>run方法才是真正的 视图开始更新方法<br>
<font color="#c41230">src/core/observer/watcher.js</font> run() <br>如果get方法存在的话,就执行get方法,<br>get方法主要做了两件事<br>1. pushTarget() 将watcher赋值给Dep.target<br>2. this.getter方法执行
Vue初始化时的挂载函数
$mount()实际就是mountComponet函数执行后
<font color="#c41230">src/core/instance/lifecycle.js</font> mountComponent() <br>挂载函数执行方法,主要工作就是用来updateComponent
updateComponent()方法主要是做了以下几点<br>1. 先render()=>vnode(虚拟DOM)<br>2. vnode=>update()=> vnode=>node
0 条评论
下一页