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
Nginx can generally be used for seven-layer load ...
<br />Related articles: 9 practical suggesti...
Preface I am used to writing less/sass, but now I...
Relationship between MySQL and MariaDB MariaDB da...
Table of contents 1. Component Registration 2. Us...
Simple example of adding and removing HTML nodes ...
The fixed IP address of the centos-DVD1 version s...
Html semantics seems to be a commonplace issue. G...
Table of contents Introduction Mirror repository ...
Table of contents 1. Values within loop objects...
What to do if VmWare cannot access the Internet w...
Download the zip installation package: Download a...
I have seen a lot of MySQL-related syntax recentl...
Previous This is a classic old question. Since a ...
question: The commonly used command "ll"...