Vue3 0 渲染流程(三)

2021-10-18 08:33:02 字數 1627 閱讀 4246

上兩篇文章分析了初次渲染大體流程,以及建立vnode過程,都比較簡單,這篇文章分析具體渲染vnode的過程。

function basecreaterenderer(

options: rendereroptions,

createhydrationfns?: typeof createhydrationfunctions

): any

} else

flushpostflushcbs()

//初次渲染後,給container物件增加乙個_vnode屬性,表示已為這個節點建立了vnode,下次就會進行

//diff更新了

container._vnode = vnode

} //....

return

}

開始patch旅程:

const patch: patchfn = (

n1,n2,

container,

anchor = null,

parentcomponent = null,

parentsuspense = null,

issvg = false,

optimized = false

) => = n2

switch (type) else if (shapeflag & shapeflags.component)

const processcomponent = (

n1: vnode | null,

n2: vnode,

container: rendererelement,

anchor: renderernode | null,

parentcomponent: componentinternalinstance | null,

parentsuspense: suspenseboundary | null,

issvg: boolean,

optimized: boolean

) => else

} else

}

const mountcomponent: mountcomponentfn = (

initialvnode,

container,

anchor,

parentcomponent,

parentsuspense,

issvg,

optimized

) =>

if (__dev__) else

} instance.root = parent ? parent.root : instance

instance.emit = emit.bind(null, instance)

if (__dev__ || __feature_prod_devtools__)

//最後返回建立的instance物件

return instance

}

最後把建立的instance物件賦值給initialvnode.component,所以下一件事就是setupcomponent(instance)。

Vue3 0系列(Vue3 0是如何變快的 )

來說一說為什麼performance 效能比vue 2.x快1.2 2倍 這裡先提供兩個 2.1 diff演算法優化 例子 我是段落 也就是說,vue3在渲染的時候,給會改變的元素新增了靜態標記 import from vue export function render ctx,cache,pro...

快速上手vue3 0

安裝最新vue腳手架 npm i vue cli g 通過腳手架建立專案,並選擇3.0 vue create vue next 執行專案 npm run serve vue2.0採用的叫做選項式api 例如我們想實現某乙個功能,關於這個功能的資料我們會定義在data中,事件函式定義在methods中...

Vue3 0學習記錄

composition api 組合api 效能提公升 viteoptions api composition api 響應式系統公升級 vue.js 3.0中使用proxy物件重寫響應式系統 proxy物件效能本身就比 defineproperty好 物件可以攔截物件的賦值 刪除等,不需要初始化遍...