Home  >  Article  >  Web Front-end  >  Detailed explanation of Vue parent-child component value transfer and slot application steps

Detailed explanation of Vue parent-child component value transfer and slot application steps

php中世界最好的语言
php中世界最好的语言Original
2018-05-22 14:54:594850browse

This time I will bring you a detailed explanation of the value transfer and slot application steps of the vue parent-child component. What are the precautions for the value transfer and slot application of the vue parent-child component. The following is a practical case, let's take a look.

1. Passing values ​​​​from parent to child components

nbsp;html>


  
  父子组件传值
  
  


  

                

{{total}}

            

2. Passing DOM from parent components to child components

Look at an example first

  

      

Qin

  

  

Open the viewer to check

Detailed explanation of Vue parent-child component value transfer and slot application steps

found that Qin is missing

Qin

1

View the official documentation, https://cn.vuejs.org/v2/guide/components-slots.html

We come to the conclusion: if child does not contain a element, any content passed into it will be discarded

We add the slot

  

      

Qin

  

  

It was found that Qin can be displayed normally, and the slot will be replaced with the parsed fragment Qin

Detailed explanation of Vue parent-child component value transfer and slot application steps

When the parent component does not respond to the child When the component passes a value, slot can also appear as the default value of the parent component

  

         

  

Rendering

Detailed explanation of Vue parent-child component value transfer and slot application steps

##Named Slot

If you want to use multiple slots, let’s take a look at the effect first:

  

             

This is header
      
This is footer
         

  

Detailed explanation of Vue parent-child component value transfer and slot application steps

It is found that multiple headers and footers appear. To solve this problem, we need to use named slots

We modify the code as follows:

  

             

This is header
      
This is footer
         

  

Detailed explanation of Vue parent-child component value transfer and slot application steps

You can see that the display is normal

I believe it After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed explanation of the steps to add, delete and modify JavaScript DOM elements

VeeValidate form verification use case in vue project Code analysis

The above is the detailed content of Detailed explanation of Vue parent-child component value transfer and slot application steps. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn