Detailed explanation of two points to note in vue3: setup

Detailed explanation of two points to note in vue3: setup

In vue2

Passing properties from parent component to child component

insert image description here

Subcomponents receive properties

insert image description here

insert image description here

If it is not received, it needs to be received in $attrs. The disadvantage is that there is no restriction on the type, and the name is relatively long when used.

insert image description here

insert image description here

The name is longer when used

insert image description here

Vue2, parent component uses slots in child components

insert image description here

insert image description here

Print the contents of a slot

insert image description here

If the parent component uses 2 slots of the child component

insert image description here

insert image description here

Parent component uses named slots in child components

insert image description here

insert image description here

In vue3

Notes on setup

insert image description here

The setup life cycle is before beforecreated

insert image description here
insert image description here

setup can get two parameters, props and context

Pass 2 properties to the child component

insert image description here

insert image description here

insert image description here

Print context

insert image description here

insert image description here

context.attrs

Similar to vue2, if only part is declared, the rest is in the attrs attribute

insert image description here

insert image description here

context.emit

Add listener events to child components

insert image description here

insert image description here

context.slot

insert image description here

insert image description here

insert image description here

If you pass a named slot

insert image description here

Or (recommended)

insert image description here

Print

insert image description here

If you pass 2 named slots

insert image description here

insert image description here

Summarize

insert image description here

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:
  • Highly recommended! Setup syntax sugar in Vue 3.2
  • Detailed explanation of props and context parameters of SetUp function in Vue3
  • Application example of setup-script in vue3
  • Detailed explanation of the usage of setUp and reactive functions in vue3
  • Vue3 setup() advanced usage examples detailed explanation
  • Front-end vue3 setup tutorial

<<:  Solve the mobile terminal jump problem (CSS transition, target pseudo-class)

>>:  Solution to the automatic termination of docker run container

Recommend

5 basic skills of topic page design (Alibaba UED Shanmu)

This topic is an internal sharing in the second h...

Docker link realizes container interconnection

Table of contents 1.1. Network access between con...

Vue imitates ElementUI's form example code

Implementation requirements The form imitating El...

WeChat applet + ECharts to achieve dynamic refresh process record

Preface Recently I encountered a requirement, whi...

About the selection of time date type and string type in MySQL

Table of contents 1. Usage of DATETIME and TIMEST...

How does JS understand data URLs?

Table of contents Overview Getting started with d...

Table setting background image cannot be 100% displayed solution

The following situations were discovered during d...

Detailed explanation of CSS float property

1. What is floating? Floating, as the name sugges...

Detailed explanation of CocosCreator Huarongdao digital puzzle

Table of contents Preface text 1. Panel 2. Huaron...

How to deploy springcloud project with Docker

Table of contents Docker image download Start mys...

How complicated is the priority of CSS styles?

Last night, I was looking at an interview question...

Create a code example of zabbix monitoring system based on Dockerfile

Use the for loop to import the zabbix image into ...

jQuery simulates picker to achieve sliding selection effect

This article shares the specific code of jQuery t...