D
D
DemetrioMoscow2021-06-18 13:04:49
Vue.js
DemetrioMoscow, 2021-06-18 13:04:49

Vue 3 events. How to set v-on for a programmatically created component?

Good day!

Please tell me how to solve the problem:

I create a component programmatically, something like this:

let component = defineComponent({
extends: ExampleComponent
});

const div = document.createElement('div');
let app = createApp(component, props).mount(div);


I want to send an event to the parent from the created component via emit. How to listen to it?

In Vue2 you could do this - app.$on('someevent', handler), what are the options in Vue 3?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kulakov, 2021-06-18
@DemetrioMoscow

Judging by this: https://v3.vuejs.org/guide/migration/events-api.ht... it is suggested to use a third-party event emitter implementation

A
aloky, 2021-06-18
@aloky

I would use dispatchEvent

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question