I have the following component with a slot:
{{ someProp }}
I looked into TypeScript definition files of Vue.js
and I found an undocumented function on Vue component instance: $createElement()
. My guess is, it is the same function that is passed to render(createElement)
function of the component. So, I am able to solve it as:
const Constr = Vue.extend(MyComponent);
const instance = new Constr({
propsData: { someProp: 'My Heading' }
});
// Creating simple slot
const node = instance.$createElement('div', ['Hello']);
instance.$slots.default = [node];
instance.$mount(body);
But this is clearly undocumented and hence questionable approach. I will not mark it answered if there is some better approach available.