From 3ef40d5a06b830264b2d62571f19a80bf5169dfc Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Thu, 1 Jul 2021 22:17:20 +0200 Subject: [PATCH] script setup fix (#74) --- src/core/Object3D.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/Object3D.ts b/src/core/Object3D.ts index 290e2d9..a355f35 100644 --- a/src/core/Object3D.ts +++ b/src/core/Object3D.ts @@ -1,5 +1,5 @@ import { Object3D, Scene } from 'three' -import { ComponentPublicInstance, defineComponent, PropType, watch } from 'vue' +import { ComponentPublicInstance, defineComponent, getCurrentInstance, PropType, watch } from 'vue' import { bindObjectProp, bindProp } from '../tools' import { RendererInjectionKey, RendererInterface } from './Renderer' import { SceneInjectionKey } from './Scene' @@ -125,6 +125,13 @@ export default defineComponent({ }, getParent(): undefined | ComponentPublicInstance { let parent = this.$parent + + if (!parent) { + // for script setup + const instance = getCurrentInstance() as any // ctx is internal + if (instance && instance.parent) parent = instance.parent.ctx + } + while (parent) { if ((parent as any).add) return parent parent = parent.$parent