Detailed explanation of slots in Vue

Detailed explanation of slots in Vue

The reuse of code in vue provides us with mixnis. The reuse of templates provides us with slots.

Slot Classification

Default Slots

Named Slots

Scoped Slots

When we only need to insert an HTML tag in our component, we can use the default slot.

If there are multiple, we need to give the first slot a name to decide which slot to insert it into.

When we want to use data from a component in our slot, we may use a scoped slot.

The following shows the usage of the default slot

insert image description here

When using

insert image description here

The above is the use of the default slot

Named slots, that is, we define one or more slots in a component, and in order to distinguish which one is acting on it, give the slot a name to distinguish

insert image description here

When using

insert image description here

Here I would like to say that Vue 2.6 version has a new way of writing slots, which uses the template tag. We know that template is just a wrapping tag, it will not be rendered on the real page. The new way of writing slots uses it. It is not enough without it, as shown below

insert image description here

Let's talk about scoped slots.

Let's take a look at the data displayed by the two slots above. They are all placed in the data of the About component, the user of the slot.

But sometimes, users don't care about these data, and the data is obtained from the category component itself.

The user About only needs to manage the presentation of the content in the slot.

This is where scoped slots come in handy

insert image description here

In the above figure, you can see that two data are passed to the user in the scope slot

How did the user receive it?

insert image description here

The above are the three types of slots used in Vue

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the usage of scoped slots in Vue.js slots
  • Detailed explanation of Vue scope slot implementation method and function
  • Detailed explanation of how to use Vue anonymous, named and scoped slots
  • Detailed explanation of using slots and clustered slots in Vue
  • Detailed explanation of vue2.6 slot update v-slot usage summary
  • Detailed explanation of scoped slots of Vue components

<<:  HTML table tag tutorial (25): vertical alignment attribute VALIGN

>>:  Implementation of Docker private library

Recommend

dl, dt, dd list label examples

The dd and dt tags are used for lists. We usually...

How to use Samba to build a shared file service on a Linux server

Recently, our small team needs to share a shared ...

Detailed explanation of Nodejs array queue and forEach application

This article mainly records the problems and solu...

MySQL data compression performance comparison details

Table of contents 1. Test environment 1.1 Hardwar...

On Visual Design and Interaction Design

<br />In the entire product design process, ...

DOM operation table example (DOM creates table)

1. Create a table using HTML tags: Copy code The ...

XHTML Getting Started Tutorial: XHTML Web Page Image Application

<br />Adding pictures reasonably can make a ...

Examples and comparison of 3 methods for deduplication of JS object arrays

Table of contents 1. Comparison of data before an...

Vue implements the browser-side code scanning function

background Not long ago, I made a function about ...

MySQL v5.7.18 decompression version installation detailed tutorial

Download MySQL https://dev.mysql.com/downloads/my...

Sample code for implementing form validation with pure CSS

In our daily business, form validation is a very ...

MySQL FAQ series: When to use temporary tables

Introduction to temporary tables What is a tempor...

MYSQL subquery and nested query optimization example analysis

Check the top 100 highest scores in game history ...