From ce2f2b7684ddbef7345cf89231ab829734139bfe Mon Sep 17 00:00:00 2001 From: pimlie Date: Tue, 15 Oct 2019 10:47:59 +0200 Subject: [PATCH] feat: return root instance if not mounted --- src/utils/createVueInstance.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/createVueInstance.js b/src/utils/createVueInstance.js index 8ab10bc..0d61777 100644 --- a/src/utils/createVueInstance.js +++ b/src/utils/createVueInstance.js @@ -99,7 +99,10 @@ export default function createVueInstance(element, Vue, componentDefinition, pro // Define the Vue constructor to manage the element element.__vue_custom_element__ = new Vue(rootElement); element.__vue_custom_element_props__ = props; - element.getVueInstance = () => element.__vue_custom_element__.$children[0]; + element.getVueInstance = () => { + const vueInstance = element.__vue_custom_element__; + return vueInstance.$children.length ? vueInstance.$children[0] : vueInstance; + }; if (options.shadow && options.shadowCss && element.shadowRoot) { const style = document.createElement('style');