vue 子组件为插槽slot提供内容

app.vue

<template>
 <h1>插槽知识</h1>
 <SmallSlot>
  <template #header>
    <div>
    <ul>
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>
  </div>
  </template>
  <template #main="slotProps">
    <h3>{{ slotProps.msg }}</h3>
    <div>
    <ul>
      <li>10</li>
      <li>20</li>
      <li>30</li>
    </ul>
  </div>
  </template>
 </SmallSlot>
</template>
<script>
import SmallSlot from './components/SmallSlot.vue'
export default{
  components:{
    SmallSlot
  }
}
</script>

SmallSlot.vue
 
<template>
   <slot name="header"></slot>
   <a href="">123</a>
   <slot name="main" :msg="amessge"></slot>

</template>

<script>
 export default {
    data(){
        return{
            amessge:'hello'
        }
    }
 }
</script>

<style>

</style>
posted @   学无边涯  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示