vue3源码阅读【runtime-core\src\component.ts】【createComponentInstance】

createComponentInstance

  • 这里 vnode 就是 由 rootComponent 执行 createVNode 后生成的 虚拟组件vnode, vnode.type 就是 rootComponent 本身,包含了 setup、methods等属性
  • 以 vnode、type等属性以及一些其他的属性 创建instance 实例。
export function createComponentInstance(
  vnode: VNode,
  parent: ComponentInternalInstance | null,
  suspense: SuspenseBoundary | null
) {
  const type = vnode.type as ConcreteComponent
  // inherit parent app context - or - if root, adopt from root vnode
  const appContext =
    (parent ? parent.appContext : vnode.appContext) || emptyAppContext

  const instance: ComponentInternalInstance = {
    uid: uid++,
    vnode,
    type,
    parent,
    appContext,
    root: null!, // to be immediately set
    next: null,
    subTree: null!, // will be set synchronously right after creation
    effect: null!,
    update: null!, // will be set synchronously right after creation
    scope: new EffectScope(true /* detached */),
    render: null,
    proxy: null,
    exposed: null,
    exposeProxy: null,
    withProxy: null,
    provides: parent ? parent.provides : Object.create(appContext.provides),
    accessCache: null!,
    renderCache: [],

    // local resolved assets
    components: null,
    directives: null,

    // resolved props and emits options
    propsOptions: normalizePropsOptions(type, appContext),
    emitsOptions: normalizeEmitsOptions(type, appContext),

    // emit
    emit: null!, // to be set immediately
    emitted: null,

    // props default value
    propsDefaults: EMPTY_OBJ,

    // inheritAttrs
    inheritAttrs: type.inheritAttrs,

    // state
    ctx: EMPTY_OBJ,
    data: EMPTY_OBJ,
    props: EMPTY_OBJ,
    attrs: EMPTY_OBJ,
    slots: EMPTY_OBJ,
    refs: EMPTY_OBJ,
    setupState: EMPTY_OBJ,
    setupContext: null,

    // suspense related
    suspense,
    suspenseId: suspense ? suspense.pendingId : 0,
    asyncDep: null,
    asyncResolved: false,

    // lifecycle hooks
    // not using enums here because it results in computed properties
    isMounted: false,
    isUnmounted: false,
    isDeactivated: false,
    bc: null,
    c: null,
    bm: null,
    m: null,
    bu: null,
    u: null,
    um: null,
    bum: null,
    da: null,
    a: null,
    rtg: null,
    rtc: null,
    ec: null,
    sp: null
  }
  if (__DEV__) {
    instance.ctx = createDevRenderContext(instance)
  } else {
    instance.ctx = { _: instance }
  }
  instance.root = parent ? parent.root : instance
  instance.emit = emit.bind(null, instance)

  // apply custom element special handling
  if (vnode.ce) {
    vnode.ce(instance)
  }

  return instance
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"error in /node_modules/vue/types/v3-component-props.d.ts" 是指在路径为 /node_modules/vue/types/v3-component-props.d.ts 的文件中发生了错误。 这个错误可能由多种原因引起,比如: 1. 文件不存在:首先要确保该文件实际上存在于所指定的路径中。如果文件不存在,就需要检查是否正确安装了相关依赖包,或者可能需要重新安装这些依赖包。 2. 依赖包版本不匹配:在不同的版本之间,依赖包的文件结构和定义可能会发生变化。如果你的项目中使用了不兼容的依赖包版本,就可能导致这个错误。可以尝试升级或降级相关的依赖包来解决这个问题。 3. TypeScript 定义文件错误:这个错误可能是由于在 TypeScript 的类型定义文件中存在错误导致的。你可以尝试查看该文件的内容,并检查其中可能存在的语法错误或声明错误。 解决这个问题的具体步骤可能因具体情况而异。可以尝试以下一些解决方法: 1. 清除缓存:尝试清除项目的缓存,可以通过删除 `node_modules` 目录下的所有内容,并重新运行 `npm install` 来重新安装依赖包。 2. 检查依赖包版本:确保项目中所使用的依赖包版本与你的项目要求的兼容。 3. 检查 TypeScript 定义文件:如果问题出现在 TypeScript 定义文件中,可以尝试定位并修复其中的错误。可以查阅 Vue.js 的文档或官方社区以获取更多关于 TypeScript 定义文件的信息和帮助。 4. 寻求帮助:如果以上方法无法解决问题,你可以在相关论坛、社区或开发者平台上寻求帮助,向其他开发者请教或提交问题报告,以获得更专业的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值