Understanding slots, named slots, and scoped slots
Slots are sections of a component where the template/rendering is delegated back to the parent of the component. We can consider slots as templates or markup that are passed from a parent to a child for rendering in its main template.
Passing markup to a component for rendering
The simplest type of slot is the default child slot.
We can define a Box
component with a slot as follows:
<template> Â Â <div> Â Â Â Â <slot>Slot's placeholder</slot> Â Â </div> </template>
The following markup is for the parent component (src/App.vue
):
<template> Â Â <div> Â Â Â Â <Box> Â Â Â Â Â Â <h3>This whole h3 is rendered in the slot</h3> Â Â Â Â </Box> Â Â </div> </template> <script> import Box from './components/Box.vue' export...