展开菜单
首页 精品内容 本月促销 装机必备 Windows PDF教程 macOS软件 IOS软件 Android AI 专题
全部分类

当前位置:

首页 > 编程开发 > vue3中的createApp怎么使用

vue3中的createApp怎么使用

函数定义createApp函数定义在文件packages/runtime-dom/src/index.ts中exportconstcreateApp=((...args)=>{constapp=ensureRenderer().createApp(...args)if(__DEV__){injectNativeTagCheck(app)injectCompilerOptionsCheck(app)}const{mount}=appapp.mount=(containerOrSelector:Element

本文目录

    函数定义

    createApp函数定义在文件 packages/runtime-dom/src/index.ts中

    export const createApp = ((...args) => {
      const app = ensureRenderer().createApp(...args)
     
      if (__DEV__) {
        injectNativeTagCheck(app)
        injectCompilerOptionsCheck(app)
      }
     
      const { mount } = app
      app.mount = (containerOrSelector: Element | ShadowRoot | string): any => {
        const container = normalizeContainer(containerOrSelector)
        if (!container) return
     
        const component = app._component
        if (!isFunction(component) && !component.render && !component.template) {
          // __UNSAFE__
          // Reason: potential execution of JS expressions in in-DOM template.
          // The user must make sure the in-DOM template is trusted. If it's
          // rendered by the server, the template should not contain any user data.
          component.template = container.innerHTML
          // 2.x compat check
          if (__COMPAT__ && __DEV__) {
            for (let i = 0; i < container.attributes.length; i++) {
              const attr = container.attributes[i]
              if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) {
                compatUtils.warnDeprecation(
                  DeprecationTypes.GLOBAL_MOUNT_CONTAINER,
                  null
                )
                break
              }
            }
          }
        }
     
        // clear content before mounting
        container.innerHTML = ''
        const proxy = mount(container, false, container instanceof SVGElement)
        if (container instanceof Element) {
          container.removeAttribute('v-cloak')
          container.setAttribute('data-v-app', '')
        }
        return proxy
      }
     
      return app
    }) as CreateAppFunction

    (1)首先创建App对象

    (2)取出app对象中的mount方法,重写mount方法

    • 首先调用 normalizeContainer 函数来获取container节点

    • 清空container的innerHTML

    • 调用原mount方法

    ensureRenderer

    其函数定义为

    function ensureRenderer() {
      return (
        renderer ||
        (renderer = createRenderer(rendererOptions))
      )
    }

    ensureRenderer通过调用createRenderer,createRenderer函数定义在 packages/runtime-core/src/renderer.ts文件中

    export function createRenderer<
      HostNode = RendererNode,
      HostElement = RendererElement
    >(options: RendererOptions) {
      return baseCreateRenderer(options)
    }

    最终是调用baseCreateRenderer,其最终返回

    return {
        render,
        hydrate,
        createApp: createAppAPI(render, hydrate)
      }

    createAppAPI

    createAppAPI函数定义在 packages/runtime-core/src/apiCreateApp.ts文件中,其返回函数

    return function createApp(rootComponent, rootProps = null)

    mount

    其定义在packages/runtime-core/src/apiCreateApp.ts文件

    mount(
            rootContainer: HostElement,
            isHydrate?: boolean,
            isSVG?: boolean
          ): any {
            if (!isMounted) {
              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.
              vnode.appContext = context
     
              // HMR root reload
              if (__DEV__) {
                context.reload = () => {
                  render(cloneVNode(vnode), rootContainer, isSVG)
                }
              }
     
              if (isHydrate && hydrate) {
                hydrate(vnode as VNode, rootContainer as any)
              } else {
                render(vnode, rootContainer, isSVG)
              }
              isMounted = true
              app._container = rootContainer
              // for devtools and telemetry
              ;(rootContainer as any).__vue_app__ = app
     
              if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
                app._instance = vnode.component
                devtoolsInitApp(app, version)
              }
     
              return vnode.component!.proxy
            } else if (__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)\``
              )
            }
          }

    (1)调用createVNode创建虚拟结点

    (2)调用 render 函数来实现渲染vnode。render函数是baseCreateRenderer 函数返回调用 createAppAPI 时传入的参数之一

    // implementation
    function baseCreateRenderer(
      options: RendererOptions,
      createHydrationFns?: typeof createHydrationFunctions
    ): any {
        ....
      const render: RootRenderFunction = (vnode, container, isSVG) => {
        if (vnode == null) {
          if (container._vnode) {
            unmount(container._vnode, null, null, true)
          }
        } else {
          patch(container._vnode || null, vnode, container, null, null, null, isSVG)
        }
        flushPostFlushCbs()
        container._vnode = vnode
      }
     .....
    }

    patch

    函数定义在 packages/runtime-core/src/renderer.ts文件中

    const patch: PatchFn = (
        n1,
        n2,
        container,
        anchor = null,
        parentComponent = null,
        parentSuspense = null,
        isSVG = false,
        slotScopeIds = null,
        optimized = __DEV__ && isHmrUpdating ? false : !!n2.dynamicChildren
      ) => {
        // patching & not same type, unmount old tree
        if (n1 && !isSameVNodeType(n1, n2)) {
          anchor = getNextHostNode(n1)
          unmount(n1, parentComponent, parentSuspense, true)
          n1 = null
        }
     
        if (n2.patchFlag === PatchFlags.BAIL) {
          optimized = false
          n2.dynamicChildren = null
        }
     
        const { type, ref, shapeFlag } = n2
        switch (type) {
          case Text:
            processText(n1, n2, container, anchor)
            break
          case Comment:
            processCommentNode(n1, n2, container, anchor)
            break
          case Static:
            if (n1 == null) {
              mountStaticNode(n2, container, anchor, isSVG)
            } else if (__DEV__) {
              patchStaticNode(n1, n2, container, isSVG)
            }
            break
          case Fragment:
            processFragment(
              n1,
              n2,
              container,
              anchor,
              parentComponent,
              parentSuspense,
              isSVG,
              slotScopeIds,
              optimized
            )
            break
          default:
            if (shapeFlag & ShapeFlags.ELEMENT) {
              processElement(
                n1,
                n2,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized
              )
            } else if (shapeFlag & ShapeFlags.COMPONENT) {
              processComponent(
                n1,
                n2,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized
              )
            } else if (shapeFlag & ShapeFlags.TELEPORT) {
              ;(type as typeof TeleportImpl).process(
                n1 as TeleportVNode,
                n2 as TeleportVNode,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized,
                internals
              )
            } else if (__FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags.SUSPENSE) {
              ;(type as typeof SuspenseImpl).process(
                n1,
                n2,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized,
                internals
              )
            } else if (__DEV__) {
              warn('Invalid VNode type:', type, `(${typeof type})`)
            }
        }
     
        // set ref
        if (ref != null && parentComponent) {
          setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2)
        }
      }
    const patch: PatchFn = (
        n1,
        n2,
        container,
        anchor = null,
        parentComponent = null,
        parentSuspense = null,
        isSVG = false,
        slotScopeIds = null,
        optimized = __DEV__ && isHmrUpdating ? false : !!n2.dynamicChildren
      ) => {
        // patching & not same type, unmount old tree
        if (n1 && !isSameVNodeType(n1, n2)) {
          anchor = getNextHostNode(n1)
          unmount(n1, parentComponent, parentSuspense, true)
          n1 = null
        }
     
        if (n2.patchFlag === PatchFlags.BAIL) {
          optimized = false
          n2.dynamicChildren = null
        }
     
        const { type, ref, shapeFlag } = n2
        switch (type) {
          case Text:
            processText(n1, n2, container, anchor)
            break
          case Comment:
            processCommentNode(n1, n2, container, anchor)
            break
          case Static:
            if (n1 == null) {
              mountStaticNode(n2, container, anchor, isSVG)
            } else if (__DEV__) {
              patchStaticNode(n1, n2, container, isSVG)
            }
            break
          case Fragment:
            processFragment(
              n1,
              n2,
              container,
              anchor,
              parentComponent,
              parentSuspense,
              isSVG,
              slotScopeIds,
              optimized
            )
            break
          default:
            if (shapeFlag & ShapeFlags.ELEMENT) {
              processElement(
                n1,
                n2,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized
              )
            } else if (shapeFlag & ShapeFlags.COMPONENT) {
              processComponent(
                n1,
                n2,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized
              )
            } else if (shapeFlag & ShapeFlags.TELEPORT) {
              ;(type as typeof TeleportImpl).process(
                n1 as TeleportVNode,
                n2 as TeleportVNode,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized,
                internals
              )
            } else if (__FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags.SUSPENSE) {
              ;(type as typeof SuspenseImpl).process(
                n1,
                n2,
                container,
                anchor,
                parentComponent,
                parentSuspense,
                isSVG,
                slotScopeIds,
                optimized,
                internals
              )
            } else if (__DEV__) {
              warn('Invalid VNode type:', type, `(${typeof type})`)
            }
        }
     
        // set ref
        if (ref != null && parentComponent) {
          setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2)
        }
      }

    processComponent

    函数定义在packages/runtime-core/src/renderer.ts文件中

    const processComponent = (
        n1: VNode | null,
        n2: VNode,
        container: RendererElement,
        anchor: RendererNode | null,
        parentComponent: ComponentInternalInstance | null,
        parentSuspense: SuspenseBoundary | null,
        isSVG: boolean,
        slotScopeIds: string[] | null,
        optimized: boolean
      ) => {
        n2.slotScopeIds = slotScopeIds
        if (n1 == null) {
          if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {
            ;(parentComponent!.ctx as KeepAliveContext).activate(
              n2,
              container,
              anchor,
              isSVG,
              optimized
            )
          } else {
            mountComponent(
              n2,
              container,
              anchor,
              parentComponent,
              parentSuspense,
              isSVG,
              optimized
            )
          }
        } else {
          updateComponent(n1, n2, optimized)
        }
      }

    比较旧的虚拟结点n1和新的虚拟节点n2,如果n1为空则挂载结点,否则更新结点。此时n1为空,执行mountComponent挂载结点

    mountComponent

    函数定义在packages/runtime-core/src/renderer.ts文件中

    const mountComponent: MountComponentFn = (
        initialVNode,
        container,
        anchor,
        parentComponent,
        parentSuspense,
        isSVG,
        optimized
      ) => {
        // 2.x compat may pre-creaate the component instance before actually
        // mounting
        const compatMountInstance =
          __COMPAT__ && initialVNode.isCompatRoot && initialVNode.component
        const instance: ComponentInternalInstance =
          compatMountInstance ||
          (initialVNode.component = createComponentInstance(
            initialVNode,
            parentComponent,
            parentSuspense
          ))
     
        // inject renderer internals for keepAlive
        if (isKeepAlive(initialVNode)) {
          ;(instance.ctx as KeepAliveContext).renderer = internals
        }
     
        // resolve props and slots for setup context
        if (!(__COMPAT__ && compatMountInstance)) {
          setupComponent(instance)
        }
     
        // setup() is async. This component relies on async logic to be resolved
        // before proceeding
        if (__FEATURE_SUSPENSE__ && instance.asyncDep) {
          parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect)
     
          // Give it a placeholder if this is not hydration
          // TODO handle self-defined fallback
          if (!initialVNode.el) {
            const placeholder = (instance.subTree = createVNode(Comment))
            processCommentNode(null, placeholder, container!, anchor)
          }
          return
        }
     
        setupRenderEffect(
          instance,
          initialVNode,
          container,
          anchor,
          parentSuspense,
          isSVG,
          optimized
        )
      }

    其执行流程为

    (1)首先调用createComponentInstance创建组件的实例对象

    (2)调用setupComponent来初始化属性及slots属性

    (3)调用设置和渲染有副作用的函数setupRenderEffect,主要是执行ReactiveEffect的run方法来执行componentUpdateFn以及调度queueJob。

    setupRenderEffect

    函数定义在packages/runtime-core/src/renderer.ts文件中,关键的是当中定义的函数componentUpdateFn

    const componentUpdateFn = () => {
          if (!instance.isMounted) {
            let vnodeHook: VNodeHook | null | undefined
            const { el, props } = initialVNode
            const { bm, m, parent } = instance
     
            effect.allowRecurse = false
            // beforeMount hook
            if (bm) {
              invokeArrayFns(bm)
            }
            // onVnodeBeforeMount
            if ((vnodeHook = props && props.onVnodeBeforeMount)) {
              invokeVNodeHook(vnodeHook, parent, initialVNode)
            }
            if (
              __COMPAT__ &&
              isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)
            ) {
              instance.emit('hook:beforeMount')
            }
            effect.allowRecurse = true
     
            if (el && hydrateNode) {
              // vnode has adopted host node - perform hydration instead of mount.
              const hydrateSubTree = () => {
        
                instance.subTree = renderComponentRoot(instance)
                
                hydrateNode!(
                  el as Node,
                  instance.subTree,
                  instance,
                  parentSuspense,
                  null
                )
                
              }
     
              if (isAsyncWrapper(initialVNode)) {
                (initialVNode.type as ComponentOptions).__asyncLoader!().then(
                  // note: we are moving the render call into an async callback,
                  // which means it won't track dependencies - but it's ok because
                  // a server-rendered async wrapper is already in resolved state
                  // and it will never need to change.
                  () => !instance.isUnmounted && hydrateSubTree()
                )
              } else {
                hydrateSubTree()
              }
            } else {
              
              const subTree = (instance.subTree = renderComponentRoot(instance))
             
              patch(
                null,
                subTree,
                container,
                anchor,
                instance,
                parentSuspense,
                isSVG
              )
              
              initialVNode.el = subTree.el
            }
            // mounted hook
            if (m) {
              queuePostRenderEffect(m, parentSuspense)
            }
            // onVnodeMounted
            if ((vnodeHook = props && props.onVnodeMounted)) {
              const scopedInitialVNode = initialVNode
              queuePostRenderEffect(
                () => invokeVNodeHook(vnodeHook!, parent, scopedInitialVNode),
                parentSuspense
              )
            }
            if (
              __COMPAT__ &&
              isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)
            ) {
              queuePostRenderEffect(
                () => instance.emit('hook:mounted'),
                parentSuspense
              )
            }
     
            // activated hook for keep-alive roots.
            // #1742 activated hook must be accessed after first render
            // since the hook may be injected by a child keep-alive
            if (initialVNode.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
              instance.a && queuePostRenderEffect(instance.a, parentSuspense)
              if (
                __COMPAT__ &&
                isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)
              ) {
                queuePostRenderEffect(
                  () => instance.emit('hook:activated'),
                  parentSuspense
                )
              }
            }
            instance.isMounted = true
            // #2458: deference mount-only object parameters to prevent memleaks
            initialVNode = container = anchor = null as any
          } else {
            // updateComponent
            // This is triggered by mutation of component's own state (next: null)
            // OR parent calling processComponent (next: VNode)
            let { next, bu, u, parent, vnode } = instance
            let originNext = next
            let vnodeHook: VNodeHook | null | undefined
     
            if (next) {
              next.el = vnode.el
              updateComponentPreRender(instance, next, optimized)
            } else {
              next = vnode
            }
     
            // Disallow component effect recursion during pre-lifecycle hooks.
            effect.allowRecurse = false
            // beforeUpdate hook
            if (bu) {
              invokeArrayFns(bu)
            }
            // onVnodeBeforeUpdate
            if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
              invokeVNodeHook(vnodeHook, parent, next, vnode)
            }
            if (
              __COMPAT__ &&
              isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)
            ) {
              instance.emit('hook:beforeUpdate')
            }
            effect.allowRecurse = true
     
            // render
            const nextTree = renderComponentRoot(instance)
            const prevTree = instance.subTree
            instance.subTree = nextTree
            patch(
              prevTree,
              nextTree,
              // parent may have changed if it's in a teleport
              hostParentNode(prevTree.el!)!,
              // anchor may have changed if it's in a fragment
              getNextHostNode(prevTree),
              instance,
              parentSuspense,
              isSVG
            )
         
            next.el = nextTree.el
            if (originNext === null) {
              // self-triggered update. In case of HOC, update parent component
              // vnode el. HOC is indicated by parent instance's subTree pointing
              // to child component's vnode
              updateHOCHostEl(instance, nextTree.el)
            }
            // updated hook
            if (u) {
              queuePostRenderEffect(u, parentSuspense)
            }
            // onVnodeUpdated
            if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
              queuePostRenderEffect(
                () => invokeVNodeHook(vnodeHook!, parent, next!, vnode),
                parentSuspense
              )
            }
            if (
              __COMPAT__ &&
              isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, instance)
            ) {
              queuePostRenderEffect(
                () => instance.emit('hook:updated'),
                parentSuspense
              )
            }
          }
        }

    如果组件没有挂载,则挂载组件,并在挂载完把组件的 isMounted 属性设置为true,表示已挂载。如果已经挂载,则更新组件。

    递归调用 patch 函数挂载组件

    processFragment

    函数定义在packages/runtime-core/src/renderer.ts文件中

    const processFragment = (
        n1: VNode | null,
        n2: VNode,
        container: RendererElement,
        anchor: RendererNode | null,
        parentComponent: ComponentInternalInstance | null,
        parentSuspense: SuspenseBoundary | null,
        isSVG: boolean,
        slotScopeIds: string[] | null,
        optimized: boolean
      ) => {
        const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''))!
        const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''))!
     
        let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2
        if (dynamicChildren) {
          optimized = true
        }
     
        // check if this is a slot fragment with :slotted scope ids
        if (fragmentSlotScopeIds) {
          slotScopeIds = slotScopeIds
            ? slotScopeIds.concat(fragmentSlotScopeIds)
            : fragmentSlotScopeIds
        }
     
        if (n1 == null) {
          hostInsert(fragmentStartAnchor, container, anchor)
          hostInsert(fragmentEndAnchor, container, anchor)
          // a fragment can only have array children
          // since they are either generated by the compiler, or implicitly created
          // from arrays.
          mountChildren(
            n2.children as VNodeArrayChildren,
            container,
            fragmentEndAnchor,
            parentComponent,
            parentSuspense,
            isSVG,
            slotScopeIds,
            optimized
          )
        } else {
          if (
            patchFlag > 0 &&
            patchFlag & PatchFlags.STABLE_FRAGMENT &&
            dynamicChildren &&
            // #2715 the previous fragment could've been a BAILed one as a result
            // of renderSlot() with no valid children
            n1.dynamicChildren
          ) {
            // a stable fragment (template root or ) doesn't need to
            // patch children order, but it may contain dynamicChildren.
            patchBlockChildren(
              n1.dynamicChildren,
              dynamicChildren,
              container,
              parentComponent,
              parentSuspense,
              isSVG,
              slotScopeIds
            )
            if (__DEV__ && parentComponent && parentComponent.type.__hmrId) {
              traverseStaticChildren(n1, n2)
            } else if (
              // #2080 if the stable fragment has a key, it's a  that may
              //  get moved around. Make sure all root level vnodes inherit el.
              // #2134 or if it's a component root, it may also get moved around
              // as the component is being moved.
              n2.key != null ||
              (parentComponent && n2 === parentComponent.subTree)
            ) {
              traverseStaticChildren(n1, n2, true /* shallow */)
            }
          } else {
            // keyed / unkeyed, or manual fragments.
            // for keyed & unkeyed, since they are compiler generated from v-for,
            // each child is guaranteed to be a block so the fragment will never
            // have dynamicChildren.
            patchChildren(
              n1,
              n2,
              container,
              fragmentEndAnchor,
              parentComponent,
              parentSuspense,
              isSVG,
              slotScopeIds,
              optimized
            )
          }
        }
      }

    (1)如果n1为空,则执行mountChildren

    (2)否则执行patchChildren

    mountChildren

    函数定义在packages/runtime-core/src/renderer.ts文件中

      const mountChildren: MountChildrenFn = (
        children,
        container,
        anchor,
        parentComponent,
        parentSuspense,
        isSVG,
        slotScopeIds,
        optimized,
        start = 0
      ) => {
        for (let i = start; i < children.length; i++) {
          const child = (children[i] = optimized
            ? cloneIfMounted(children[i] as VNode)
            : normalizeVNode(children[i]))
          patch(
            null,
            child,
            container,
            anchor,
            parentComponent,
            parentSuspense,
            isSVG,
            slotScopeIds,
            optimized
          )
        }
      }

    遍历children,执行patch挂载所有子元素

    processElement

    函数定义在packages/runtime-core/src/renderer.ts文件中

    const processElement = (
        n1: VNode | null,
        n2: VNode,
        container: RendererElement,
        anchor: RendererNode | null,
        parentComponent: ComponentInternalInstance | null,
        parentSuspense: SuspenseBoundary | null,
        isSVG: boolean,
        slotScopeIds: string[] | null,
        optimized: boolean
      ) => {
        isSVG = isSVG || (n2.type as string) === 'svg'
        if (n1 == null) {
          mountElement(
            n2,
            container,
            anchor,
            parentComponent,
            parentSuspense,
            isSVG,
            slotScopeIds,
            optimized
          )
        } else {
          patchElement(
            n1,
            n2,
            parentComponent,
            parentSuspense,
            isSVG,
            slotScopeIds,
            optimized
          )
        }
      }

    (1)如果n1为空,则调用mountElement挂载元素

    (2)如果n1不为空,则调用patchElement来更新元素

    此时,执行挂载元素。

    mountElement

    函数定义在packages/runtime-core/src/renderer.ts文件中

    const processElement = (
        n1: VNode | null,
        n2: VNode,
        container: RendererElement,
        anchor: RendererNode | null,
        parentComponent: ComponentInternalInstance | null,
        parentSuspense: SuspenseBoundary | null,
        isSVG: boolean,
        slotScopeIds: string[] | null,
        optimized: boolean
      ) => {
        isSVG = isSVG || (n2.type as string) === 'svg'
        if (n1 == null) {
          mountElement(
            n2,
            container,
            anchor,
            parentComponent,
            parentSuspense,
            isSVG,
            slotScopeIds,
            optimized
          )
        } else {
          patchElement(
            n1,
            n2,
            parentComponent,
            parentSuspense,
            isSVG,
            slotScopeIds,
            optimized
          )
        }
      }

    (1)调用hostCreateElement根据类型和其他属性,创建DOM元素节点

    (2)判断子节点的类型,若子节点为纯文本,则直接处理纯文本hostSetElementText,若子节点为数组,则调用 mountChildren 函数深度遍历处理子节点

    (3)处理 props 属性,主要是调用hostPatchProp和setScopeId

    (4)调用hostInsert将el挂载到 container 中

    本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系bd@zhengruan.com
    作者最新文章
    编程开发 Vue3
    相关文章 更多
    精品专题 更多
    装机必备

    正软商城装机必备专区,精选办公、浏览器、安全防护、影音播放、压缩解压、设计创作和系统工具等电脑常用正版软件,帮助用户快速完成新电脑软件配置。

    Windows

    正软商城Windows软件专区,汇集适用于Windows电脑的办公、设计、安全防护、影音播放、开发工具和系统优化软件,提供软件介绍、系统要求、正版授权及购买下载服务。

    PDF教程

    正软商城PDF教程频道提供PDF编辑、转换、合并、拆分、压缩及格式处理方法,同时介绍常用PDF软件和工具的使用技巧。

    macOS软件

    正软商城macOS软件专区,精选适用于Mac电脑的办公、设计、影音、效率、开发和系统工具,提供软件功能介绍、macOS兼容版本、正版授权及购买下载服务。

    IOS软件

    正软商城iOS软件专区,精选适用于iPhone和iPad的办公、学习、影音、设计、效率及AI应用,提供功能介绍、适用设备、系统要求和正版获取方式等信息。

    AI

    正软商城AI软件专区,汇集AI写作、AI绘画、AI视频、AI办公、AI编程、AI翻译、智能客服和数据分析等人工智能工具,提供功能介绍、适用平台、收费方式及正版购买信息。

    Mac软件 更多
    Adobe Acrobat Pro macOS版
    Adobe Acrobat Pro macOS版

    Adobe Acrobat Pro 是面向办公、法务、财务、教育及出版用户的专业PDF处理软件,可在Mac上创建、编辑、转换、合并和保护文档,并提供OCR文字识别、表单、批注、内容比较、敏感信息遮盖及电子签名功能。

    Blender
    Blender

    Blender 是一款免费开源、跨平台的专业 3D 创作软件,集建模、动画、渲染、视频编辑与视觉合成等功能于一体,广泛应用于影视动画、游戏设计和建筑可视化等领域。软件支持 Cycles 物理渲染器与 Eevee 实时渲染引擎,并提供多边形建模、骨骼绑定、物理模拟等专业工具。Blender 兼容 Windows、macOS 和 Linux 系统,安装包轻巧、运行流畅,依托活跃的全球开发者社区持续更新,是从初学者到专业创作者都值得选择的正版 3D 创作工具。

    Shapr3D macOS版
    Shapr3D macOS版

    Shapr3D是一款面向工业设计、机械工程、建筑概念和三维打印工作流的CAD软件。Mac版采用Parasolid建模内核,支持草图约束、实体建模、工程图、可视化渲染及常见CAD格式交换,并可通过账户在多台设备之间同步项目。

    Adobe Illustrator macOS版
    Adobe Illustrator macOS版

    Adobe Illustrator 是 Adobe 推出的专业矢量图形设计软件,适合在 Mac 上制作标志、图标、插画、包装、信息图及印刷版面。它以路径和锚点构建可无损缩放的图形,并提供钢笔、形状、文字、图像描摹、渐变、画板及生成式功能。

    Adobe InDesign macOS版
    Adobe InDesign macOS版

    Adobe InDesign 是面向印刷品与数字出版物的专业版面设计软件,可在 Mac 上制作书籍、杂志、宣传册、海报、报告及交互式文档。它提供精细的文字样式、网格、母版、长文档管理和印前输出能力。

    Affinity Designer macOS版
    Affinity Designer macOS版

    Affinity Designer 的矢量设计能力现已整合进 Affinity by Canva,可在 Mac 上进行标志、图标、插画、界面原型及印刷品设计。个人用户使用免费 Canva 账户即可使用完整的矢量、像素和版面工具。

    Archicad macOS版
    Archicad macOS版

    Archicad是Graphisoft推出的建筑信息模型设计软件,可在Mac上完成概念设计、参数化建模、图纸编制、工程量统计、渲染展示及团队协同。模型与平立剖面、明细表和布局保持关联,适合建筑师、室内设计师、BIM团队及相关专业学生使用。

    AutoCAD LT macOS版
    AutoCAD LT macOS版

    AutoCAD LT是Autodesk推出的专业二维CAD设计与文档编制软件,Mac版本提供原生界面、多点触控及分屏查看体验。用户可精确创建和编辑DWG图形,完成图层管理、尺寸标注、表格、PDF参考、外部参照及打印输出。

    AutoCAD macOS版
    AutoCAD macOS版

    AutoCAD for Mac 是 Autodesk 面向 macOS 提供的专业计算机辅助设计软件,支持精确的二维绘图、标注、布局输出以及实体、曲面和网格建模。软件采用适配 Mac 操作习惯的界面,可处理 DWG 图纸。

    Autodesk Fusion macOS版
    Autodesk Fusion macOS版

    Autodesk Fusion 是面向产品设计与制造的一体化云连接平台,在 Mac 上提供参数化建模、自由曲面、装配、工程图、仿真、PCB 设计和 CAM 加工等工具。它适合机械工程师、工业设计师、创客及制造团队使用。

    Autodesk Maya macOS版
    Autodesk Maya macOS版

    Autodesk Maya是一套面向影视动画、游戏开发和视觉特效制作的专业三维创作软件,集多边形与曲面建模、角色绑定、关键帧动画、动力学模拟、程序化特效及Arnold渲染于一体,并提供脚本、插件和开放式制作管线支持。

    Blender macOS版
    Blender macOS版

    Blender是一款免费开源的综合三维创作软件,可在Mac上完成建模、数字雕刻、材质制作、角色绑定、动画、物理模拟、渲染、合成及视频剪辑。软件提供Cycles与Eevee渲染工具,并支持几何节点、蜡笔绘制和Python扩展。

    WINDOWS 更多
    AutoCAD Windows版
    AutoCAD Windows版

    AutoCAD 是 Autodesk 推出的专业计算机辅助设计软件,Windows 版支持精确二维绘图、三维实体与曲面建模、图纸标注、布局发布和任务自动化,并包含多套行业专业化工具组合,适用于建筑、机械、电气、工程建设及制造设计人员。

    Adobe Acrobat Pro Windows版
    Adobe Acrobat Pro Windows版

    Adobe Acrobat Pro 是面向专业 PDF 工作的综合解决方案,可在 Windows 中创建、编辑、转换、比较、整理和保护文档,并支持表单、电子签名、扫描件文字识别及敏感信息永久遮盖。订阅还包含网页、移动服务和云端协作能力,

    Blender
    Blender

    Blender 是一款免费开源、跨平台的专业 3D 创作软件,集建模、动画、渲染、视频编辑与视觉合成等功能于一体,广泛应用于影视动画、游戏设计和建筑可视化等领域。软件支持 Cycles 物理渲染器与 Eevee 实时渲染引擎,并提供多边形建模、骨骼绑定、物理模拟等专业工具。Blender 兼容 Windows、macOS 和 Linux 系统,安装包轻巧、运行流畅,依托活跃的全球开发者社区持续更新,是从初学者到专业创作者都值得选择的正版 3D 创作工具。

    3dmax(3ds max)
    3dmax(3ds max)

    Autodesk 3ds Max 是一款专业的三维建模、动画与渲染软件,广泛应用于建筑可视化、游戏开发、影视动画、广告设计和产品展示等领域。

    Adobe InDesign Windows版
    Adobe InDesign Windows版

    Adobe InDesign 是面向印刷与数字出版的专业页面排版工具,可制作书籍、杂志、宣传册、海报、交互式 PDF 和电子书。它提供精细的文字样式、多页面管理、印前检查及多格式输出能力,并能与 Photoshop、Illustrator

    Adobe Illustrator Windows版
    Adobe Illustrator Windows版

    Adobe Illustrator 是用于绘制矢量图形、插画、图标、徽标和版式的专业设计工具。它以路径和锚点为核心,作品放大后仍能保持清晰,并提供画板、文字、渐变、图像描摹及精确变换等功能,适合品牌视觉、印刷物料、数字界面和商业插画创作。

    Figma Windows版
    Figma Windows版

    Figma 是面向产品设计与开发团队的云端协作平台,可在 Windows 桌面客户端中完成界面绘制、组件管理、交互原型、评论评审和开发交付。文件保存在云端,多名成员能够同步编辑并共享设计系统;官方同时提供免费 Starter 方案及按席位计

    Affinity Designer Windows版
    Affinity Designer Windows版

    Affinity Designer 是面向矢量图形、数字插画和界面设计的专业创作工具,可在矢量、像素与导出工作区之间快速切换。它提供曲线编辑、形状构建、画板、排版、图层和专业色彩管理,并支持常见设计文件的导入及多种印刷、网页格式输出。

    Cinema 4D Windows版
    Cinema 4D Windows版

    Cinema 4D是Maxon推出的专业三维创作软件,将建模、动画、MoGraph动态图形、粒子与动力学模拟、材质灯光及Redshift渲染整合在统一工作环境中,适用于广告包装、影视特效、产品和建筑可视化、游戏素材等制作场景。

    Blender Windows版
    Blender Windows版

    Blender 是免费开源的三维创作套件,在 Windows 上提供建模、雕刻、材质、动画、物理模拟、合成、跟踪、视频剪辑及 Cycles、EEVEE 渲染工具。它适合个人创作者、学生和小型工作室,

    Autodesk Maya Windows版
    Autodesk Maya Windows版

    Autodesk Maya 是面向影视、电视、动画和游戏行业的专业三维制作软件,集多边形与 NURBS 建模、角色绑定、关键帧和动作捕捉动画、Bifrost 特效模拟、材质开发及 Arnold 渲染于一体,

    SketchUp Pro Windows版
    SketchUp Pro Windows版

    SketchUp Pro 是面向建筑、室内、景观、施工和产品设计等专业场景的三维建模工具,提供桌面建模、LayOut 二维文档、模型资源库、扩展程序及云端协作能力。其操作逻辑直观,适合从概念推敲、空间规划到图纸表达和方案汇报的完整工作流程。