详解
vue实现了一套内容分发的API,将 slot 元素作为承载分发的出口
应用场景
父组件文字内容、或者html代码,需要在子组件指定位置展示
代码示例
父组件:
<template>
<view>
<componentA>
Your Profile
</componentA>
</view>
</template>
componentA组件:
<template>
<view>
<!-- 我是子组件componentA -->
<view >{{title}}</view>
<!--1、当组件渲染时solt元素会被替换为【Your Profile】;
2、插槽内可以包含任何模版代码
3、如果子组件的模版中没有包含solt元素,
则该组件起始标签和结束标签之间的任何内容都会被抛弃-->
<slot></slot>
</view>
</template>