vue组件中的作用域插槽

插槽<slot>可以在父组件使用子组件时,改变子组件类容。

作用域插槽可以使得父组件页面可以使用子组件的数据:v-slot

v-slot具名插槽使用

<template v-slot:header>
    <h1>Here might be a page title</h1>
</template>
相当于
<template slot="header">
<h1>Here might be a page title</h1>
</template>

v-slot作用域插槽使用

<template v-slot:default="slotProps">
    {{ slotProps.user.firstName }}
</template>
当子组件为默认插槽时可以写为(当被提供的内容只有默认插槽时,组件的标签才可以被当作插槽的模板来使用)
<template v-slot="slotProps">
    {{ slotProps.user.firstName }}
</template>

slot-scope:可以获取父组件传递给子组件的数据一般在<tempate>中使用

复制代码
<el-table :data="btnTableData" style="width: 100%">
<el-table-column prop="menuUses" label="适用对象">
            <template slot-scope="scope">
              <span v-if="scope.row.menuUses">企业</span>
            </template>
 </el-table-column>
</el-table>
复制代码

 

posted on   马玉豪  阅读(77)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示