美文网首页
Vue插槽slot的用法

Vue插槽slot的用法

作者: 扣丁李 | 来源:发表于2021-09-28 02:43 被阅读0次

子组件

<template>
    <div class="card-box">
        <div class="card-head">
            <slot name="card-head"></slot>
        </div>
        <div class="card-body">
            <slot></slot>
        </div>
    </div>
</template>

<script>
</script>

<style scoped="scoped">
    .card-box{
        border: 1px solid cornflowerblue;
        border-radius: 2px;
        width: 400px;
        min-height: 200px;
    }
    .card-head{
        height: 50px;
        line-height: 50px;
        text-align: left;
        padding: 0 5px;
        color: white;
        font-size: 18px;
        background-color: cornflowerblue;
    }
    .card-body{
        text-align: left;
        padding: 0 5px;
    }
</style>

父组件

<template>
    <div id="app">
        <Card>
            <template slot="card-head">头部</template>
            我是内容
        </Card>
    </div>
</template>

<script>
    import Card from './components/Card.vue'

    export default {
        name: 'app',
        components: {
            Card
        },
        data(){
            return{
        
            }
        },
        methods:{
            
        }
    }
</script>

<style>
    #app {
        font-family: 'Avenir', Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-align: center;
        color: #2c3e50;
        margin-top: 60px;
    }
</style>

效果

image.png

相关文章

  • Vue之深入理解插槽—slot, slot-scope, v-s

    Vue 2.6.0 以前Vue 2.6.0 以后具名插槽 slot具名插槽 v-slot作用域插槽 slot-sc...

  • vue插槽

    vue插槽slot的理解与使用 vue slot插槽的使用介绍及总结

  • 详解Vue的slot新用法

    摘要: 理解Vue插槽。 作者:前端小智 原文:vue 2.6 中 slot 的新用法 Fundebug经授权转载...

  • vue中的slot(插槽)

    vue中的插槽————slot 什么是插槽? 插槽(Slot)是Vue提出来的一个概念,正如名字一样,插槽用于决定...

  • vue slot插槽

    v-slot 插槽的用法: 单个slot内容时: 子组件: 父组件: 多个slot内容时(具名插槽): 子组件: ...

  • 推陈出新,v-slot的用法

    前言:最近在学vue,发现slot插槽已经在vue2.6就被舍弃了,新增了v-slot用法,去看了官网实在没看懂如...

  • Vue插槽slot的用法

    子组件 父组件 效果

  • vue 插槽的使用

    vue 插槽手册 深入理解vue中的slot与slot-scope 插槽的使用其实是很简单首先要明白插槽是使用在子...

  • 18、Vue3 作用域插槽

    作用域插槽:让插槽内容能够访问子组件中,vue2中作用域插槽使用slot-scope,vue3中使用v-slot ...

  • slot是什么?有什么作用?原理是什么?

    slot又名插槽,是Vue的内容分发机制,组件内部的模板引擎使用slot元素作为承载分发内容的出口。插槽slot是...

网友评论

      本文标题:Vue插槽slot的用法

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