Vue_04(插槽)

发布时间:2022-06-27 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Vue_04(插槽)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

定义插槽slot

  插槽的使用过程其实是抽取共性、预留不同;  我们会将共同的元素、内容依然在组件内进行封装;  同时会将不同的元素使用slot作为占位,让外部决定到底显示什么样的元素;

插槽 | Vue.js https://v3.cn.vuejs.org/guide/component-slots.htML#%E6%8F%92%E6%A7%BD%E5%86%85%E5%AE%B9

注意:父级模板里的所有内容都是在父级作用域中编译的;子模板里的所有内容都是在子作用域中编译的。

具名插槽

# 1
<div class="container">
  <header>
    <!-- 我们希望把页头放这里 -->
  </header>
  <;main>
    <!-- 我们希望把主要内容放这里 -->
  </main>
  <footer>
    <!-- 我们希望把页脚放这里 -->
  </footer>
</div>
# 2
<div class="container">
  <header>
    <slot name="header"></slot>
  </header>
  <main>
    <slot></slot>
  </main>
  <footer>
    <slot name="footer"></slot>
  </footer>
</div>
# 3
<base-layout>
  <template v-slot:header>
    <h1>Here might be a page tITle</h1>
  </template>

  <template v-slot:default>
    <p>A paragraph for the main content.</p>
    <p>And another one.</p>
  </template>

  <template v-slot:footer>
    <p>Here's some contact info</p>
  </template>
</base-layout>

作用域插槽&nbsp;https://v3.cn.vuejs.org/guide/component-slots.html#%E4%BD%9C%E7%94%A8%E5%9F%9F%E6%8F%92%E6%A7%BD

具名插槽的缩写 https://v3.cn.vuejs.org/guide/component-slots.html#%E5%85%B7%E5%90%8D%E6%8F%92%E6%A7%BD%E7%9A%84%E7%BC%A9%E5%86%99

脚本宝典总结

以上是脚本宝典为你收集整理的Vue_04(插槽)全部内容,希望文章能够帮你解决Vue_04(插槽)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。