Vue slot nesting

there are two child components in the parent component: child component 1 nested child component 2
and child component 1 and child component 2 both have < slot >

result:
1. Sub-component 1 slot does not write name, sub-component 2 slot writes name= "content", and
content can be rendered normally.

2. Subcomponent 1 slot writes name= "panel", subcomponent 2 slot writes name= "content",
can only render the slot contents of subcomponent 1.

3. Sub-component 1 and sub-component 2 slot do not write name,
content can be rendered normally.

I would like to ask why this result occurs.

//1: panel.vue
<template>
<div>
  <slot name="panel"></slot>
</div>
</template>

//2 : content.vue
<template>
<div>
  <slot name="content"></slot>
</div>
</template>

//
<template>
<panel>
  <h1 slot="panel">panel</h1>
  <content>
    <p  slot="content">content

</content> </panel> </template> <script> import Panel from "@/common/panel" import Content from "@/common/content" </script>
Apr.02,2021

I think it may be the problem of nesting content under your panel. It may be caused by the nesting of content under panel but not giving content a slot, in panel.

  1. Sub-component 1 slot does not write name, while sub-component 2 slot writes name= "content". The content can be rendered normally.
    reason: sub-component 1 does not write name,. At this time, the slot slot content is the original sub-component 1 slot content and sub-component 2 content. (anonymous slot)

2. Sub-component 1 slot writes name= "panel", and sub-component 2 slot writes name= "content", which can only render the slot content of sub-component 1.
reason: named slot, only the corresponding content will be displayed. At this time, slot is to help < H1 slot= "panel" > I am panel < / H1 > to occupy a seat.
3. Both Sub-component 1 and Sub-component 2 slot do not write name, and can only render the slot contents of Sub-component 1.
this normal situation shows that the slot in panel is the same as the situation, and the slot in content can also display the corresponding slot content. (can't figure it out)


you are a nested component in a component. In the first case, panel is not a named slot, which is equivalent to the whole

.
<h1 slot="panel">panel</h1>
<content>
<p slot="content">content

</content>

insert it into panel div. You say panel component < slot name= "panel" > < / slot > do not write name
< slot > < / slot > then it should not render that I am panel H1

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38885-2c101.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38885-2c101.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?