62
rated 0 times
[
64]
[
2]
/ answers: 1 / hits: 8024
/ 3 Years ago, wed, october 27, 2021, 12:00:00
I have a Vue 2 pattern I was using for a common scenario: programmatically creating an instance to open a Modal/Dialog/Lightbox on dynamic content outside of a template.
In Vue 2, I found this pattern:
// DialogService.js
export default {
alert(text) {
const DialogClass = Vue.extend(DialogComponentDef);
let dialog = new DialogClass({ propsData: { text } });
dialog.$on('close', () => {
dialog.$destroy();
dialog.$el.remove();
dialog = null;
});
// mount the dynamic dialog component in the page
const mountEl = document.createElement('div');
document.body.appendChild(mountEl);
dialog.$mount(mountEl);
},
};
How can I acheive this in Vue 3, knowing Vue.extends
, $on
& $destroy
do not exist anymore?
You can see a full example of the DialogService.js by clicking here.
More From » vue.js