Slots Unification

Overview

This change unifies normal and scoped slots in 3.x.

Here is a quick summary of what has changed:

  • this.$slots now exposes slots as functions
  • BREAKING: this.$scopedSlots is removed

For more information, read on!

2.x Syntax

When using the render function, i.e., h, 2.x used to define the slot data property on the content nodes.

  1. // 2.x Syntax
  2. h(LayoutComponent, [
  3. h('div', { slot: 'header' }, this.header),
  4. h('div', { slot: 'content' }, this.content)
  5. ])

In addition, when referencing scoped slots, they could be referenced using the following syntax:

  1. // 2.x Syntax
  2. this.$scopedSlots.header

3.x Syntax

In 3.x, render functions will have a slots option where they can be defined instead.

  1. // 3.x Syntax
  2. h(LayoutComponent, {
  3. slots: {
  4. header: () => h('div', this.header),
  5. content: () => h('div', this.content)
  6. }
  7. })

And when you need to reference scoped slots programmatically, they are now unified into the $slots option.

  1. // 2.x Syntax
  2. this.$scopedSlots.header
  3. // 3.x Syntax
  4. this.$slots.header

Migration Strategy

A majority of the change has already been shipped in 2.6. As a result, the migration can happen in one step:

  1. Replace all this.$scopedSlots occurrences with this.$slots in 3.x.