What is a slotA slot is a placeholder in a child component that is provided to a parent component, represented by <slot></slot>. The parent component can fill any template code in this placeholder, such as HTML, components, etc. The filled content will replace the <slot></slot> tag of the child component. Understanding of default slotsJust use the full tag () to write the corresponding configuration in its full tag (for example: the functions we need) Then use the default slot tag to put the written content into this slot (this slot generally exists in the child component, so you can give the child component what the parent component has written) Regarding the configuration style written in the complete tag, we can write it in both the parent component and the child component (because, 1. When the style is written in the parent component, the style has been rendered and then put into the child component; 2. When the style is written in the child component, put the configuration into the slot, and the child component where the slot is located has a CSS style that will render our configuration) Code Snippet①Category.vue <template> <div class="category"> <h3>{{ title }}Category</h3> <!-- Define a default slot, then the content of the tag body in the corresponding component tag in App.vue will be placed in this slot--> <slot></slot> </div> </template> <script> export default { name: "Category", props: ["title"], }; </script> <style> .category { background-color: skyblue; width: 200px; height: 300px; } h3 { text-align: center; background-color: orange; } </style> ②App.vue <template> <div class="container"> <Category title="Food"> <img src="https://zqcdn.itzjj.cn/static/skin/mfw0321/static/picture/dj_scv.jpg" alt="1" /> </Category> <Category title="Games" :listData="games"> <ul> <!-- At this time, because the variables are directly in app.vue, you can directly traverse game After traversing, use the slot function to pass it to Category.vue --> <li v-for="(g, index) in games" :key="index"> {{ g }} </li> </ul></Category > <Category title="Movies" :listData="films"> <!-- controls allow the video to play --> <video Controls src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" ></video> </Category> </div> </template> <script> import Category from "./components/Category"; export default { name: "App", components: { Category }, data() { return { foods: ["fire", "your meat", "meatballs"], games: ["Red Alert Online", "Cross Fire", "Audition"], films: ["The Godfather", "Shock Wave", "Awesome"], }; }, }; </script> <style> .container { display: flex; justify-content: space-around; } video width: 100%; } img { width: 100%; } </style> SummarizeThis is the end of this article about vue default slot. For more relevant vue default slot content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed process of deploying MySQL with docker (common applications deployed with docker)
>>: How to set a dotted border in html
1. Statistics of PV and IP Count the PV (Page Vie...
I encountered a very unusual parameter garbled pro...
Preface: I have always wanted to know how a SQL s...
Table of contents Deploy httpd with docker contai...
This article aims to clarify the relationship bet...
Table of contents ReactRouterV6 Changes 1. <Sw...
Preface In order to reflect the difference betwee...
Often you will encounter a style of <a> tag...
1. Key points for early planning of VMware vSpher...
Here is an introduction to changing the password ...
Copy code The code is as follows: <HTML> &l...
The first time I used the essay, I felt quite awkw...
1. Create the backup.sh script file #!/bin/sh SOU...
Preface I have been working on some front-end pro...
For detailed documentation on installing the comp...