vue插槽

单个插槽(默认插槽)

<template>
    <div class="father">
        <h3>这里是父组件</h3>
        <son>
            <div class="tmpl">
              <span>xxxxxxxx</span>
            </div>
        </son>
    </div>
</template>

<script>
import son from '../components/son'
export default {
    data(){
        return{

        }
    },
    components: {
        son: son
    }
}
</script>
<template>
    <div class="child">
        <h3>这里是子组件</h3>
        <slot></slot>
    </div>
</template>

具名插槽:

<template>
    <div class="father">
        <h3>这里是父组件</h3>
        <son name="jmcx">
            <div class="tmpl">
              <span>xxxxxxxx</span>
            </div>
        </son>
    </div>
</template>

<script>
import son from '../components/son'
export default {
    data(){
        return{

        }
    },
    components: {
        son: son
    }
}
</script>
<template>
    <div class="child">
        <h3>这里是子组件</h3>
        <slot class="jmcx"></slot>
    </div>
</template>

作用域插槽:

<template>
    <div class="father">
        <h3>这里是父组件</h3>
        <son name="jmcx">
            <template slot-scope="user">
            <ul>
                <li v-for="(item, index) in user.data" :key="index">{{item}}</li>
            </ul>
            </template>
        </son>
    </div>
</template>

<script>
import son from '../components/son'
export default {
    data(){
        return{

        }
    },
    components: {
        son: son
    }
}
</script>

 

<template>
    <div class="child">
        <h3>这里是子组件</h3>
        <slot class="jmcx" :data='data'></slot>
    </div>
</template>

<script>
export default {
    data(){
        return{
            data: ['11', '22', '33', '44', '55', '66']
        }
    }
}
</script>

 

posted @ 2020-05-06 11:17  _Lawrence  阅读(178)  评论(0编辑  收藏  举报