vue3插槽用法

152 阅读1分钟

slot作用

其本质是一套内容分发API,<slot> 元素作为承载分发内容的出口。其有一个特殊的 attribute:name。通过它可以为不同的插槽分配独立的 ID,也就能够以此来决定内容应该渲染到什么地方。

vue2的slot用法

<div slot="name">具名插槽</div>

vue3的slot用法

<template v-slot:name>具名插槽</template>