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

How to install MySQL 8.0 and log in to MySQL on MacOS

Follow the official tutorial, download the instal...

How to get the intersection/difference/union of two sets in mysql

Common scenarios of MySQL: getting the intersecti...

How to transfer files between Windows and Linux

File transfer between Windows and Linux (1) Use W...

mysql 8.0.15 winx64 decompression version graphic installation tutorial

Every time after installing the system, I have to...

Solution to forgetting the password of the pagoda panel in Linux 3.X/4.x/5.x

Enter ssh and enter the following command to rese...

Tutorial on installing mongodb under linux

MongoDB is cross-platform and can be installed on...

Detailed explanation of how to use several timers in CocosCreator

1. setTimeOut Print abc after 3 seconds. Execute ...

How to remove the dividing line of a web page table

<br />How to remove the dividing lines of a ...

A complete record of a Mysql deadlock troubleshooting process

Preface The database deadlocks I encountered befo...

Page Refactoring Skills - Content

Enough of small talk <br />Based on the lar...

Detailed explanation of nginx shared memory mechanism

Nginx's shared memory is one of the main reas...

In-depth explanation of the locking mechanism in MySQL

Preface In order to ensure the consistency and in...