或者

99.插槽

作者: 一土二月鸟 | 来源:发表于2020-10-05 09:50 被阅读0次

写法1

子组件:
通过 <slot name="header"> </slot> 定义子组件

父组件
通过<template slot="header">或者<template #header>

写法2

子组件:
通过 <slot name="header" :childName="123"> </slot> 定义子组件

父组件
通过<template v-slot:header="slotProps">{{slotProps.childName}}</template>

不定义name则为default,template未指定slot则进入default

适用场景

  • form表单
  • swiper轮播图

相关文章

  • 99.插槽

    写法1 子组件:通过 定义子组件 父组件通过