> For the complete documentation index, see [llms.txt](https://devworkshops.gitbook.io/masteringvuejs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devworkshops.gitbook.io/masteringvuejs/getting-started/slots.md).

# Slots

Slots are really handy when you want to replace an entire section of your component. In our example, we're going to update the `remaining-items` component and introduce slots. We will replace the contents of the success message using`<slot></slot>`

{% code title="main.js" %}

```javascript
...
Vue.component("remaining-items", {
  props: ["remaining"],
  template: `
    <div class="alert alert-danger" v-if="remaining>10">
      You've got a long day ahead of you!!!
    </div>
    <div class="alert alert-secondary" v-else-if="remaining>0">
      {{ remaining }} item(s) remaining.
    </div>
    <div class="alert alert-success" v-else>
      <slot></slot>
    </div>`
});
...
```

{% endcode %}

Now, to define our success message, we can simply add content inside the component tag as follows:

{% code title="index.html" %}

```markup
...
<remaining-items :remaining="todos.filter(t => !t.done).length">
    Hooray!!! You're all done, go to the beach!!!
</remaining-items>
...
```

{% endcode %}

You can also provide a default value for the content of the slot. To achieve this, simply add content inside of the slot area as shown below. The default content will only be replaced if content is provided when using the component.

{% code title="main.js" %}

```javascript
...
Vue.component("remaining-items", {
  props: ["remaining"],
  template: `
    ...
    <div class="alert alert-success" v-else>
      <slot>Hooray!!! You're all done, go to the beach!!!</slot>
    </div>`
});
...
```

{% endcode %}

There will also be times when you want multiple slots in a single component. This can be achieved by adding a named slot as below:

{% code title="main.js" %}

```javascript

...
Vue.component("remaining-items", {
  props: ["remaining"],
  template: `
    <div class="alert alert-danger" v-if="remaining>10">
      <slot name='danger'>You've got a long day ahead of you!!!</slot>
    </div>
    <div class="alert alert-secondary" v-else-if="remaining>0">
      {{ remaining }} item(s) remaining.
    </div>
    <div class="alert alert-success" v-else>
      <slot name='success'>Hooray!!! You're all done, go to the beach!!!</slot>
    </div>`
});
...
```

{% endcode %}

Now you have the option to pass both success and danger messages as shown below

{% code title="index.html" %}

```markup
...
<remaining-items :remaining="todos.filter(t => !t.done).length">
  <template v-slot:success>Excellent!!! Enjoy your day!!!</template>
  <template v-slot:danger>Run run run</template>
</remaining-items>
...

```

{% endcode %}

Save the your changes and verify that number of remaining items is correct, and updates when items are added or marked as done.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://devworkshops.gitbook.io/masteringvuejs/getting-started/slots.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
