[Vuejs]-Slot content of template into my inline component

0👍

Use Vue.extend({}) to have types inference.

Returning this.$slots.default is fine as long as the slot contains a single element (because Vue 2 can’t render multiple fragments).

const myBodyComponent = Vue.extend({
  render(h) {
    return this.$slots.default
      ? this.$slots.default.find(vnode => vnode.tag)!
      : h('span')
  }
})

If it can happen the slot contains multiple elements, instead:

return h('div', this.$slots.default)

Leave a comment