vue源碼之首次渲染過程詳解
首次渲染
src/core/instance/index.js 中的 this._init方法
init方法內(nèi)部
$mount內(nèi)部 - 編譯版本內(nèi)部邏輯
$mount內(nèi)部 - 運(yùn)行時版本內(nèi)部邏輯(最終執(zhí)行) runtime/index中的 $mount方法
進(jìn)入runtime/index中的$mount方法可以看到最終調(diào)用了mountComponent函數(shù)來渲染dom
core/instance/lifecycle 中的mountComponent
src/core/observer/watcher
總結(jié)
首次渲染過程
- vue初始化 實(shí)例成員 靜態(tài)成員
- new Vue()
- this._init()
- vm.$mount() - src/platforms/web/entry-runtime-with-compiler.js
- 如果沒有傳遞render,把模版編譯成render函數(shù)
- compileToFunctions()生成render()渲染函數(shù)
- options.render = render
- vm.$mount() runtime/index中定義的 $mount 最終調(diào)用了mountComponent函數(shù)
- mountComponent(this,el) - src/core/instance/lifecycle.js
- 判斷是否有render選項(xiàng),如果沒有但是傳入了模版,并且當(dāng)前是開發(fā)環(huán)境的話會發(fā)送警告
- 觸發(fā)beforeMount
- 定義 updateComponent
- 創(chuàng)建watcher實(shí)例
- 觸發(fā)mounted
- return vm
- watcher.get()
- 創(chuàng)建完watcher之后會調(diào)用一次get
- 調(diào)用updateComponent函數(shù)
- 調(diào)用 vm._render函數(shù)創(chuàng)建VNode
- 調(diào)用render.call(vm._renderProxy, vm.$createElement)
- 調(diào)用實(shí)例化時vue傳入的render 函數(shù)
- 或者編譯template生成的render
- 返回vnode
- 調(diào)用vm._update內(nèi)部調(diào)用vm.__patch__方法掛載真實(shí)dom 記錄 vm.$el
總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
深入探索Vue中樣式綁定的七種實(shí)現(xiàn)方法
在?Vue.js?開發(fā)中,合理地控制元素的樣式對于構(gòu)建高質(zhì)量的用戶界面至關(guān)重要,Vue?提供了靈活的方式來綁定樣式,這篇文章將探索?Vue?中設(shè)置樣式的七種做法,并結(jié)合代碼,逐步說明每種方法的實(shí)現(xiàn),需要的朋友可以參考下2024-03-03vue?長列表數(shù)據(jù)刷新的實(shí)現(xiàn)及思考
這篇文章主要為大家介紹了vue?長列表數(shù)據(jù)刷新的實(shí)現(xiàn)及思考,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04原生JS?Intersection?Observer?API實(shí)現(xiàn)懶加載
這篇文章主要為大家介紹了原生JS?Intersection?Observer?API實(shí)現(xiàn)懶加載示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07vue實(shí)現(xiàn)移動端input上傳視頻、音頻
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)移動端input上傳視頻、音頻,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-08-08