插槽
  # 作用域插槽
使用场景:插槽获取子组件数据
<!--child.vue-->
<template>
  <div class="child-box">
    <p>我是子组件</p>
    <slot name="header" text="我是子组件小猪课堂" :count="1"></slot>
  </div>
</template>
 1
2
3
4
5
6
7
2
3
4
5
6
7
<!--App.vue-->
<template>
  <img alt="Vue logo" src="./assets/logo.png"/>
  <child>
    <!-- 可以用解构 -->
    <template #header="{ text, count }">
      <div>{{ text }}---{{ count }}</div>
    </template>
  </child>
</template>
 1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 参考:
编辑  (opens new window)
  上次更新: 2023/01/05