Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements an alternative approach to consuming slots through the use of a new
$$slots
variable. The need for something like this has been brought up several times see #2106 and to a lesser extent #4036 there's a few more related issues scattered around.$$slots
$$slots
is an object keyed by slot name containing slot constructors of the formslot_name(ctx?: Object, callback?: Function)
.Parameters
ctx
is an optional parameter to set the inital context of the slot. Equivalent to passing props to a<slot />
node.callback
is also optional. It's a callback function that will be called when slot content changes.Return value
The constructor returns an object of the form
content
is an array containing the top level nodes. Some more work is needed to support if, each, and await blocks.The
mount
function can be called to insert the slot content into the DOM. Note that this isn't required, you could do whatever you want with the content.You can call
update
to modify the context you initially passed in. This is similar toComponent.$set
.The
destroy
function removes the content from the dom.Examples
Setting a textarea from slot content.
A react style portal component.
A nav element that sets the
active
class on child ancher elements.