Created
April 22, 2020 20:44
-
-
Save JosielFaleiros/32213885ac94cb75352ec6dae7fba7a7 to your computer and use it in GitHub Desktop.
Vue Create Componant Programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createComponent(Component, Container, propsData = {}, onClose = () => {}) { | |
const ComponentClass = Vue.extend(Component) | |
const instance = new ComponentClass({ | |
propsData | |
}) | |
// instance.$slots.default = ['Click me!'] | |
instance.$on('close', () => { | |
Container.removeChild(instance.$el) | |
instance.$destroy() | |
onClose() | |
}) | |
instance.$mount() // pass nothing | |
Container.appendChild(instance.$el) | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment