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

A brief talk about React Router's history

If you want to understand React Router, you shoul...

JavaScript Regular Expressions Explained

Table of contents 1. Regular expression creation ...

js+canvas realizes code rain effect

This article shares the specific code of js+canva...

Vue sample code for implementing two-column horizontal timeline

Table of contents 1. Implement the component time...

Detailed steps for adding hosts you need to monitor in zabbix

Add monitoring host Host 192.168.179.104 is added...

In-depth analysis of MySQL query interception

Table of contents 1. Query Optimization 1. MySQL ...

Detailed explanation of Angular data binding and its implementation

Table of contents Preface What is data binding? T...

MySQL 5.7.18 free installation version configuration tutorial

MySQL 5.7.18 free installation version installati...

Two ways to implement HTML to randomly drag content positions

Test: Chrome v80.0.3987.122 is normal There are t...

Let’s take a look at JavaScript precompilation (summary)

JS running trilogy js running code is divided int...

Network management and network isolation implementation of Docker containers

1. Docker network management 1. Docker container ...

Getting Started Tutorial on Animating SVG Path Strokes Using CSS3

Without relying on JavaScript, pure CSS is used t...

Detailed explanation of MySQL 8.0 atomic DDL syntax

Table of contents 01 Introduction to Atomic DDL 0...