mount(
rootContainer: HostElement,
isHydrate?:boolean,
isSVG?:boolean):any{// 若还未渲染if(!isMounted){//调用createVNode获取vnode,rootComponent即为调用createApp(config)的时候传递进来的config数据,rootProps为root props,前面提到过会对此进行校验,一般在使用过程中rootProps为null;const vnode =createVNode(
rootComponent as ConcreteComponent,
rootProps
)// store app context on the root VNode.// this will be set on the root instance on initial mount.//存储context到根节点上
vnode.appContext = context
// HMR root reloadif(__DEV__){
context.reload=()=>{render(cloneVNode(vnode), rootContainer, isSVG)}}// 调用渲染函数,核心渲染代码为render函数if(isHydrate && hydrate){hydrate(vnode as VNode<Node, Element>, rootContainer asany)}else{render(vnode, rootContainer, isSVG)}// isMounted置为true
isMounted =true// 实例的_container保存为当前rootContainer;
app._container = rootContainer
// for devtools and telemetry// rootContainer增加属性__vue_app__,置为当前app实例;(rootContainer asany).__vue_app__ = app
if(__DEV__ || __FEATURE_PROD_DEVTOOLS__){
app._instance = vnode.component
devtoolsInitApp(app, version)}// 返回vnode.component的代理 return vnode.component!.proxy
}elseif(__DEV__){warn(`App has already been mounted.\n`+`If you want to remount the same app, move your app creation logic `+`into a factory function and create fresh app instances for each `+`mount - e.g. \`const createMyApp = () => createApp(App)\``)}}