作用域插槽

作者: 椰果粒 | 来源:发表于2018-08-03 10:33 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>插槽</title>
    <script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <child>
            
        </child>
    </div>
    <script>
        var child = {
            data : function(){
                return {
                    lists : [1,2,3,4,5,6]
                }
            },
            template : `<div>
                <ul>
                    <li v-for="item of lists">{{item}}</li>
                </ul>
            </div>`
        }
        var vm = new Vue({
            el : "#app",
            components : {
                child : child
            }
        })
    </script>
</body>
</html>
<body>
    <div id="app">
        <child>
            <!-- template是固定写法,props是传递过来的值 -->
            <template slot-scope="props">
                <h1>{{props.item}}</h1>
            </template>
        </child>
    </div>
    <script>
        var child = {
            data : function(){
                return {
                    lists : [1,2,3,4,5,6]
                }
            },
            template : `<div>
                <ul>
                    <slot 
                        v-for="item of lists"
                        :item=item
                    ></slot>
                </ul>
            </div>`
        }
        var vm = new Vue({
            el : "#app",
            components : {
                child : child
            }
        })
    </script>
</body>

相关文章

  • 2.插槽

    匿名插槽 具名插槽 作用域插槽

  • vue----slot插槽

    插槽分类 匿名插槽 具名插槽 作用域插槽

  • jsx中插槽的写法

    作用域插槽 scopedSlots: (2.6.0+) 一个暴露传入的作用域插槽的对象。也以函数形式暴露普通插槽。...

  • vue3中的插槽

    插槽 默认插槽 具名插槽,v-slot可以简写为# 动态插槽 #[dynamicSlotName] 作用域插槽(...

  • Vue中 的作用域插槽

    逻辑:父组件调用子组件的时候,给子组件传了一个插槽,这个插槽叫做作用域插槽,作用域插槽必须是template开头和...

  • Vue-使用插槽

    二。具名卡槽 作用域插槽:插槽循环时使用

  • 2019-02-15 vue组件基础篇5

    作用域插槽续此例的用意主要是介绍作用域插槽的用法1.允许组件自定义应该如何渲染列表每一项。2.作用域插槽的使用场景...

  • vue中slot插槽的使用

    插槽的种类:1、默认插槽、具名插槽、作用域插槽、解构插槽、动态插槽几种。转原文:https://www.jians...

  • 18、Vue3 作用域插槽

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

  • 插槽

    默认插槽: 具名插槽:slot name='footer' 作用域插槽:v-slot===slot-scope 默...

网友评论

    本文标题:作用域插槽

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