小编you*_*suf的帖子

如何在组件中只使用一个命名插槽?

`我有一个包含不同插槽的组件,例如:

页眉插槽、主插槽和页脚插槽

基础布局.vue

<template>
  <div class="container">
    <header>
      <slot name="header"></slot>
    </header>
    <main>
      <slot></slot>
    </main>
    <footer>
      <slot name="footer"></slot>
    </footer>
  </div>
</template>
Run Code Online (Sandbox Code Playgroud)

我有另一个组件(主)用于渲染到屏幕。

<template>
  <base-layout>
    <template v-slot:header>
      <h2>Hello world</h2>
    </template>
  </base-layout>
</template>
Run Code Online (Sandbox Code Playgroud)

Inside Main component I need only to use header slot, instead when I try to do so all the other slots are also getting picked up

vue.js

2
推荐指数
1
解决办法
33
查看次数

标签 统计

vue.js ×1