




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
上一章我們在分 的html,像上一章的例子那樣是一個普通
VNode節(jié)點(diǎn),否則通 方法創(chuàng)建一個組件VNodeifif(typeoftag==='string')letns=(context.$vnode&&context.$vnode.ns)||config.getTagNamespaceifTag(tag))tformbuilt-invnode=new tformTagName(tag),data,children,undefined,undefined,context)}elseif(isDef(Ctor=resolveAsset(context.$options,'components',tag))){//vnodeponent(Ctor,data,context,children,}else//unknownorunlistednamespaced//checkatruntimebecauseitmaygetassignedanamespacewhens//parentnormalizesvnode=newVNode(tag,data,children,undefined,undefined,)}}}else//directcomponentoptions/vnodeponent(tag,data,context,}App對象,它本質(zhì)上是一個它會走到上述代碼的else
vnode
exportexportponentCtor:Class<Component>|Function|Object|data:?VNodeData,context:Component,children:?Array<VNode>,tag?:string):VNode|Array<VNode>|void{if(isUndef(Ctor)){}constbaseCtor=inoptionsobject:turnitintoaif(isObject(Ctor))Ctor=}//ifatthisstageit'snotaconstructororanasynccomponent//if(typeofCtor!=='function')if(process.env.NODE_ENV!=='production')warn(`InvalidComponentdefinition:${String(Ctor)}`,}}//asyncletif(isUndef(Ctor.cid))asyncFactory=Ctor ponent(asyncFactory,baseCtor,if(Ctor===undefined)//return ceholdernodeforasynccomponent,whichis//asacommentnodebutpreservesalltherawinformationforthenode.//theinformationwillbeusedforasyncserver-renderingandhyreturn )}}data=data||//resolveconstructoroptionsincaseglobalmixinsareappliedr//componentconstructor//transformcomponentv-modeldataintoprops&if(isDef(data.model))transformModel(Ctor.options,}//extractconstpropsData=extractPropsFromVNodeData(data,Ctor,//functionalif(isTrue(Ctor.options.functional))returnc ponent(Ctor,propsData,data,context,ch}//extractlisteners,sincetheseneedstobetreated//childcomponentlistenersinsteadofDOMconstlisteners=// cewithlistenerswith.native//soitgetsprocessedduringparentcomponentdata.on=if )) componentsdonotkeep//otherthanprops&listeners&//workaroundconstslot=data=if(slot)data.slot=}}//installcomponentmanagementhooksonto ceholder//return ceholderconstname=C||constvnode=new ponent-${Ctor.cid}${name?`-${name}`:data,undefined,undefined,undefined,{Ctor,propsData,listeners,tag,children)//Weexspecific:invokerecycle-listoptimized@renderfunction//extractingcell-slot /*istanbulignoreifif(WEEX ponent(vnode))return }returnreturn}
case3vnodeconstconstbaseCtor=inoptionsobject:turnitintoaif(isObject(Ctor))Ctor=}App.vueoWorldfromexportdefaultname:'app',components:}}export的是一個對象,所以baseCtor.extend(Ctor),在這里最開始初始化Vue
Vue中 函數(shù)有這么一段邏輯////thisisusedtoidentifythe"base"constructortoextend//componentswithinWeex'smulti-instanceVue.options._baseVue.options._base=context.$options,實(shí)際上在
Vue vm.$options=mergeOptions(vm.$options=mergeOptions(options||{},)這樣就把Vue上的一 擴(kuò)展到了vm.$option上,所以我們也就能 拿到Vue這個構(gòu)造函數(shù)了。mergeOptions的實(shí)現(xiàn)我們會Vue 和用戶傳入 上src/core/global-src/core/global-
Vue之后,我們來看一下
*ClassVue.extend=function(extendOptions:Object):Function{extendOptions=extendOptions||{}constSuper=constSuperId=constcachedCtors=extendOptions._Ctor||(extendOptions._Ctor={})if(cachedCtors[SuperId]){return}constname=extendO||Sif(process.env.NODE_ENV!=='production'&&name){}constSub= ponent(options)}Stotype=Stotype.constructor=Sub.cid=Sub.options=)Sub['super']=//Forpropsandcomputedproperties,wedefine getters//theVueinstancesatextensiontime,ontheextendedprototype.//avoidsObject.definePropertycallsforeachinstanceif(Sps)}if puted)}//allowfurtherextension/mixin/pluginSub.extend=Sub.mixin=Sub.use=////createassetregisters,soextended//canhavetheirprivateassetstoo.ASSET_TYPES.forEach(function(type)Sub[type]=//enablerecursiveself-lookupif(name){ponents[name]=}//keepareferencetothesuperoptionsatextension//lateratinstantiationwecancheckifSuper'soptions//beenupdated.Sub.superOptions=Super.optionsSub.extendOptions=extendOptionsSub.sealedOptions=extend({},Sub.options)//cacheconstructorcachedCtors[SuperId]=SubreturnSub}
optionsAPI 構(gòu)造函數(shù)做了緩存避免多次執(zhí)
邏輯再次走到 constconstSub=ponent(options)}////installcomponentmanagementhooksontoceholderVue.jsVirtualDOMsnabbdom,它的一個特點(diǎn)是在VNode的patch流程中對外了各種時機(jī)的鉤子函數(shù),方便我們做一些額外的事情,Vue.js也是充分利用這一點(diǎn),在初始化一個Component類型的VNode的過程中實(shí)現(xiàn)了幾個鉤子函數(shù):constconstcomponentVNodeHooks=init(vnode:VNodeWithData,hydrating:boolean):?boolean{if(ponentInstance&&ponentInstance._isDestroyed&&)//kept-alivecomponents,treatasaconstmountedNode:any=vnode//workaroundflowcomponentVNodeHooks.prepatch(mountedNode,mountedNode)}elseconstchildponentInstance)child.$mount(hydrating?vnode.elm:undefined,}prepatchde)ponentVNode,constoptionsconstchild ponentInstance psData,//updatedoptions.listeners,//updatedvnode,//newparentoptions.children//new)insert ponentVNode)const{context,componentInstance}=if(!componentInstance._isMounted)componentInstance._isMounted=callHook(componentInstance,}if(vnode.data.keepAlive)if(context._isMounted)//vue-//Duringupdates,akept-alivecomponent'schildcomponentsy//change,sodirectlywalkingthetreeheremaycall//onincorrectchildren.Insteadwepushthemintoaqueuech//beprocessedafterthewholepatchprocess}elseponent(componentInstance,true/*direct}}destroy ponentVNode)const{componentInstance}=if(!componentInstance._isDestroyed)if(!vnode.data.keepAlive)}elseponent(componentInstance,true/*direct}}}}consthooksToMerge= ponentHooks(data:VNodeData)consthooks=data.hook||(data.hook=for(leti=0;i<hooksToMerge.length;i++)constkey=constexisting=consttoMerge=if(existing!==toMerge&&!(existing&&existing._merged))hooks[key]=existing?mergeHook(toMerge,existing):}}}functionfunctionmergeHook(f1:any,f2:any):Function{constmerged=(a,b)=>{//flowcom insaboutextraargswhichiswhyweuseanyf1(a,b)f2(a,}merged._merged=truereturnmer
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 辦公室租賃合同范本
- 農(nóng)業(yè)種植包工合同范本
- 農(nóng)田施工工程合同范本
- 共同承包協(xié)議工程合同范本
- 會林租賃合同范本
- 勞動關(guān)系聯(lián)營合同范本
- 現(xiàn)澆橋面板腳手架施工方案
- 陜西涼亭廊架施工方案
- 2025四川內(nèi)江川豫汽車銷售服務(wù)有限公司招聘15人筆試參考題庫附帶答案詳解
- 農(nóng)村拆遷土地合同范本
- 2023年煙臺南山學(xué)院單招綜合素質(zhì)考試筆試題庫及答案解析
- 基于Matlab的并行計算課件
- 2021年熔化焊與熱切割基礎(chǔ)知識課件
- 瀝青試驗(yàn)講解精品課件
- 秒的認(rèn)識 完整版PPT
- 創(chuàng)新藥產(chǎn)業(yè)鏈研究培訓(xùn)框架
- 燃?xì)鈽I(yè)務(wù)代辦授權(quán)書模板
- 大音希聲話古韻——古琴曲《流水》課件
- 《中國人閱讀書目(三)——中國初中生基礎(chǔ)閱讀書目-導(dǎo)賞手冊》新書簡介2014.8.14 (1)
- 智利國家英文介紹PPT精選文檔
- 金蝶K3 Cloud 產(chǎn)品安裝指南
評論
0/150
提交評論