Preface Named slots are bound to elements using the "name" attribute in the slot. Notice: 1. If no match is found, put it in an anonymous slot 2. The rendering order of named slots depends entirely on the template, not on the order of elements in the parent component Vue's anonymous slot (default slot)Parent Component <div> <myslot>I just now</myslot> </div> Subcomponents <div> <slot><slot> </div> Vue's named slotsParent Component <div> <myslot> <template #one>Piggy is a big fat cat</template> <template #two>They are all big assholes</template> <template #three>Mimi is a heartless little bastard</template> I just now </div> Subcomponents <div> <slot name="one"></slot> <slot><slot> <slot name="two"></slot> <slot name="three"></slot> </div> Rendered (in approximate order) is vue scoped slotsExplain scope slots in plain language: parent components can read the data carried by the corresponding slots of child components through slots. <div> <myslot> <template #oneData="oneData"> <div>{{oneData.one.message}}</div> </template> <template #two>They are all big assholes</template> <template #three>Mimi is a heartless little bastard</template> I just </myslot> </div> Subcomponents <div> <slot name="one" :data='one'></slot> <slot><slot> <slot name="two"></slot> <slot name="three"></slot> </div> <script> export default { data() { return { one: { message: 'This is the data message of the subcomponent', }, }; }, } </script> Code Optimization <div> <myslot> <template #oneData="{oneData}"> <div>{{oneData.message}}</div> </template> <template #two>They are all big assholes</template> <template #three>Mimi is a heartless little bastard</template> I just now </div> Subcomponents <div> <slot name="one" :oneData='one'></slot> <slot><slot> <slot name="two"></slot> <slot name="three"></slot> </div> <script> export default { data() { return { one: { message: 'This is the data message of the subcomponent', }, }; }, } </script> SummarizeThis is the end of this article about the basic use of vue named slots. For more relevant vue named 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 explanation of two methods for setting global variables and session variables in MySQL
>>: Do you know how many connections a Linux server can handle?
Recently, I encountered the need to embed a player...
Table of contents 1. Build the Vue environment 2....
There are some tags in XHTML that have similar fu...
Table of contents Introduction to utf8mb4 UTF8 by...
Table of contents 1. Project construction 2: Dire...
Table of contents Overview File Descriptors Synch...
0. Background Hardware: Xiaomi Notebook Air 13/In...
The error "mysql is not an internal command&...
Before I start, let me emphasize that process.env...
environment: MAC_OS 10.12 Python 3.6 mysql 5.7.25...
This article mainly introduces the installation/st...
1. v-on event monitoring To listen to DOM events,...
Preface In the previous article, we mainly learne...
<br />The most common mistake made by many w...
1. The difference between Http and Https HTTP: It...