Vue3项目中slot插槽不起作用(解决方法)

修改:使用的每一个slot都需要一个 template 包裹,且 slot=“名称” 修改为 v-slot:名称

原来的写法:

//子组件
<template>
  <div class="tab-bar-item">
      <slot name="item-icon"></slot>
  </div>
</template>
 
//父组件
<tab-bar-item>
   <img slot="item-icon" src="../src/assets/img/tabbar/home.svg" alt="" />
</tab-bar-item>    

修改后的写法:

//父组件,子组件无需修改
<tab-bar-item>
  <template v-slot:item-icon>
    <img src="../src/assets/img/tabbar/home.svg" alt="" />
  </template>
</tab-bar-item>

猜你喜欢

转载自blog.csdn.net/qq_46617584/article/details/130683872
今日推荐