My Vue 3 application is as follow:
app.js
import { createApp } from "vue";
import App from "./app.vue";
let vm = createApp(App)
vm.mount("#app");
window.vm = vm
app.vue
<script>
export default {
name: "App",
methods: {
async someMethod() {
this.data.push(1);
}
//...
}
</script>
In Vue 2, it is possible to reach internal methods using the following code:
vm.$children[0].someMethod()
However, it does not work with Vue3.
How can I integrate my Vue component to an external API using a similar technique in Vue 3?
2
Answers
This question was answered by Estus Flask in the comments section.
app.js
In Vue 3, to access the internal methods of a component, you should consider using
defineExpose
to expose the method in that componenthttps://vuejs.org/api/sfc-script-setup.html#defineexpose