脚本宝典收集整理的这篇文章主要介绍了Vue_04(插槽),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
插槽的使用过程其实是抽取共性、预留不同; 我们会将共同的元素、内容依然在组件内进行封装; 同时会将不同的元素使用slot作为占位,让外部决定到底显示什么样的元素;
# 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>
以上是脚本宝典为你收集整理的Vue_04(插槽)全部内容,希望文章能够帮你解决Vue_04(插槽)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。