美文网首页
Vue 插槽

Vue 插槽

作者: Cherry丶小丸子 | 来源:发表于2022-04-19 16:25 被阅读0次
组件定义 <base-layout></base-layout>
<div class="container">
    <header>
        <slot name="header" :row="row"></slot>
    </header>
    <main>
        <slot name="default" :row="row"></slot>
    </main>
    <footer>
        <slot name="footer" :row="row"></slot>
    </footer>
</div>
vue 2.*
<base-layout>
    <template slot="header" slot-scope="scope">
        {{ scope.row }}
    </template>
    <template slot="default" slot-scope="scope">
        {{ scope.row }}
    </template>
    <template slot="footer" slot-scope="scope">
        {{ scope.row }}
    </template>
</base-layout>

// 简写
<base-layout>
    <template slot="header" slot-scope="scope">
        {{ scope.row }}
    </template>
    <template slot-scope="scope">
        {{ scope.row }}
    </template>
    <template slot="footer" slot-scope="scope">
        {{ scope.row }}
    </template>
</base-layout>
vue 3.*
<base-layout>
    <template v-slot:header="scope">
        {{ scope.row }}
    </template>
    <template v-slot:default="scope">
        {{ scope.row }}
    </template>
    <template v-slot:footer="scope">
        {{ scope.row }}
    </template>
</base-layout>

// 简写
<base-layout>
    <template #header="scope">
        {{ scope.row }}
    </template>
    <template #default="scope">
        {{ scope.row }}
    </template>
    <template #footer="scope">
        {{ scope.row }}
    </template>
</base-layout>

相关文章

网友评论

      本文标题:Vue 插槽

      本文链接:https://www.haomeiwen.com/subject/pggsertx.html