yarn add mount-vue-component
import { mount } from 'mount-vue-component'
import { h } from 'vue'
const comp = {
props: ['name'],
setup: (props) => () => h('h1', `Hello, ${props.name}!`),
unmounted() { console.log("Bye") },
mounted() { console.log("Hi") }
}
const { vNode, destroy, el } = mount(comp, { props: { name: 'world' } })
component
: required, the component to be created/mountedprops
: props to be passed onto the component, this can include HTML attributes likeid
orclass
children
: components to be rendered as children ofcomponent
element
: if specified, the element to mount the component into, if not specified, adiv
will be createdapp
: the Vue app instance fromcreateApp
, if provided will be bound to the component'sappContext
vNode
: the instance of the component provideddestroy
: a function that will unmount and destroy the componentel
: will provide the HTML element the component is mounted into