vue slot


The v-slot directive was introduced in Vue 2.6.0, offering an improved, alternative API to the still-supported slot and slot-scope attributes. The slot and slot-scope attributes will continue to be supported in all future 2.x releases, but are officially deprecated and will eventually be removed in Vue 3. To demonstrate this, we’ll need a completely different example component with slots, one that’s even more contrived than the previous one: let’s sorta copy the example from the docs by creating a component that supplies the data about the current user to its slots: This component has a property called user with details about the user.

我们为每个 todo 准备了一个插槽, Components were always designed to be able to be reused, but some patterns aren’t practical to enforce with a single “normal” component because the number of props you’ll need in order to customize it can be excessive or you’d need to pass large sections of content and potentially other components through the props. If you’re new to Vue or haven’t seen the changes from version 2.6, read on. Now, in the parent scope, we can use v-slot with a value to define a name for the slot props we’ve been provided: In this example, we’ve chosen to name the object containing all our slot props slotProps, but you can use any name you like. Slot name Description; label: The label value that will appear before or after the input element, default is a