首页 > 其他 > 详细

vue作用域插槽

时间:2019-11-20 23:54:16      阅读:119      评论:0      收藏:0      [点我收藏+]

   简而言之,作用域插槽就是让插槽内容能够访问子组件中的数据。


案例如下:有CurUser组件

<template>
    <span>
        <!-- 在slot 元素上绑定user,让父组件插槽能够访问 -->
        <slot :user="user"></slot>
    </span>
</template>

<script>
    export default {
        data() {
            return {
                user: {
                    firstName: "张",
                    lastName: "三"
                }
            }
        }
    }
</script>
<style scoped>
</style>

使用组件

        <cur-user>
            <!-- 使用slot-scope 或者v-slot 来接收-->
            <template slot-scope="scope">
                {{scope.user.firstName}} {{scope.user.lastName}}
            </template>
        </cur-user>

 

 

 

vue作用域插槽

原文:https://www.cnblogs.com/jlyuan/p/11901934.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!