Skip to content

getParentInstance

getParentInstance(options, instance?): void | ComponentInternalInstance

通过 name、ID、Ref 或组件名称多种方式获取父级实例

参数

NameTypeDescription
optionsObject选项对象,包含要查询的属性和名称,任选其一即可
options.componentNameundefined | string组件名称
options.idundefined | string组件ID
options.nameundefined | string组件名称
options.refundefined | string组件Ref
instance?ComponentInternalInstance当前实例

返回值

void | ComponentInternalInstance

父级组件实例

示例

ts
const parentInstance = getParentInstance({
  componentName: 'share-root',
})

const parentInstance = getParentInstance({
  id: 'share-root',
})

源码

get-parent-instance.js