When it comes to component communication, there are probably five types that are familiar to everyone: 1. From father to sonThe parent component passes values to the child component through custom attributes, and the child component receives them using props 2. From son to fatherThe parent component customizes the event on the child component tag, and the child component triggers the custom event through $emit and can pass parameters 3. Non-parent-child component value transfer eventBus event bus: Information can be published and subscribed through eventBus (creating an event bus that everyone can access) 4. vuexVuex is a state management mode developed specifically for Vue.js applications. It uses a centralized storage manager to manage the status of all components of the program and solve multi-component communication. However, it is mostly used in medium and large projects, and it will appear bloated in small projects. 5. RefsBy adding ref and ·$refs·, you can also easily get the child component and access the properties and methods of the child component. Regarding refs, I have also written a separate article with detailed usage, the usage of refs In addition to the above 5, there are 5 less common component communication methods: 6. $children In the parent component, $children returns a component collection. If you know the order of the child components, you can also use the subscript operation 7. $parent In the child component For example: 8. provide & inject Appear in pairs : provide and inject appear in pairs Function : Used by parent components to pass data to descendant components Directions:
9. $attrsUsed by parent components to pass data to grandchild components 10. $listeners Used by grandchild components to pass data to parent components SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Docker5 full-featured harbor warehouse construction process
>>: Introduction to the use of data custom attributes in HTML and plug-in applications
How to add <script> script in HTML: 1. You c...
1. Download 2. Decompression 3. Add the path envi...
Linux and Unix are multi-user operating systems, ...
The final effect is as follows: The animation is ...
Pull the image # docker pull codercom/code-server...
This article example shares the specific code of ...
Question 1: The writing method that will report a...
1. Normal background blur Code: <Style> htm...
<br />In general guestbooks, forums and othe...
The definition and inheritance of classes in JS a...
Preface Due to the weak typing of JS, loose writi...
1. Syntax TIMESTAMPDIFF(unit,begin,end); Returns ...
Table of contents 1. JavaScript is single-threade...
Chapter 1 Source Code Installation The installati...
Confluence is paid, but it can be cracked for use...