zoukankan      html  css  js  c++  java
  • 作用域插槽模板迭代的次数,取决于组件内部独立slot的数量

    第一种情况:内部有两个独立插槽(模板自动迭代2次)

    <!DOCTYPE html>
    <html>
    
    <head>
        <title> hello world vue </title>
        <meta charset="utf-8" />
    </head>
    
    <body>
        <div id="app" v-cloak>
            <child-component>
                <template scope="props">
                    <p>来自父组件的内</p>
                    <p> {{props.msg1}}</p>
                    <p> {{props.msg2}}</p>
                    <p> {{props}}</p>
                    <hr>
                </template>
            </child-component>
        </div>
    </body>
    
    </html>
    
    <script src="jquery-3.1.1.js"></script>
    <script src="vue.js"></script>
    
    
    <script>
        $(document).ready(function() {
    
        });
    </script>
    
    
    <script>
        var bus = new Vue();
    
        Vue.component('child-component', {
            template: '
                    <div class="container">
                         <slot msg1="来自子组件的内容1"></slot>
                         <slot msg2="来自子组件的内容2"></slot>
                    <div>',
            props: [],
            data: function() {
                return {}
            },
            methods: {}
        });
    
        var app = new Vue({
            el: '#app',
            data: {
                showChild: true
            },
            computed: {},
            methods: {},
            components: {},
            mounted: function() {}
        });
    </script>
    来自父组件的内
    
    来自子组件的内容1
    
    { "msg1": "来自子组件的内容1" }
    
    ---------------------------------------
    来自父组件的内 来自子组件的内容2 { "msg2": "来自子组件的内容2" }

    第二种情况:内部有1个独立插槽(虽然有两个变量,模板仅仅迭代一次)

    <!DOCTYPE html>
    <html>
    
    <head>
        <title> hello world vue </title>
        <meta charset="utf-8" />
    </head>
    
    <body>
        <div id="app" v-cloak>
            <child-component>
                <template scope="props">
                    <p>来自父组件的内</p>
                    <p> {{props.msg1}}</p>
                    <p> {{props.msg2}}</p>
                    <p> {{props}}</p>
                    <hr>
                </template>
            </child-component>
        </div>
    </body>
    
    </html>
    
    <script src="jquery-3.1.1.js"></script>
    <script src="vue.js"></script>
    
    
    <script>
        $(document).ready(function() {
    
        });
    </script>
    
    
    <script>
        var bus = new Vue();
    
        Vue.component('child-component', {
            template: '
                    <div class="container">
                         <slot msg1="来自子组件的内容1" msg2="来自子组件的内容2"></slot>
                    <div>',
            props: [],
            data: function() {
                return {}
            },
            methods: {}
        });
    
        var app = new Vue({
            el: '#app',
            data: {
                showChild: true
            },
            computed: {},
            methods: {},
            components: {},
            mounted: function() {}
        });
    </script>
    来自父组件的内
    
    来自子组件的内容1
    
    来自子组件的内容2
    
    { "msg1": "来自子组件的内容1", "msg2": "来自子组件的内容2" }
  • 相关阅读:
    AcWing 157. 树形地铁系统 (hash判断树同构)打卡
    AcWing 156. 矩阵 (哈希二维转一维查询)打卡
    AcWing 144. 最长异或值路径 01字典树打卡
    AcWing 143. 最大异或对 01字典树打卡
    AcWing 142. 前缀统计 字典树打卡
    AcWing 139. 回文子串的最大长度 hash打卡
    AcWing 138. 兔子与兔子 hash打卡
    常用C库函数功能及用法
    编程实现C库函数
    C语言面试题5
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/11479386.html
Copyright © 2011-2022 走看看