I am creating a web-component using VueJS 3, I want to expose a method on the component allowing the user to do something like this:
<custom-component id="x1" />
<script>
var component = document.getElementById("x1");
component.customMethod(); // as focus() method on native elements
</script>
If I define a method on the component, I can call the method inside the component. But the method is not available when I use it as a web-component.
//main.ts/js
import { defineCustomElement } from "vue"
import component from "./component.ce.vue"
const element = defineCustomElement(component );
customElements.define("custom-component ", element);
//component.ce.vue
const customMethod = () => { console.log("Executed"); }
How I can indicate to Vue Component Wrapper that the customMethod will be available outside the component?
_instance
in a component defined with a.ce.vue
file that hasdefineExpose({ .. })
doesn't work and the methods are not available for calling. -1 for this answer. There is a bug report considered to be a feature request, which is a clear regression from 2.x (github.com/vuejs/core/issues/5540) that is over a year old and nobody is looking into solving the problem. β Inunction