zoukankan      html  css  js  c++  java
  • 作用域插槽

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8"/>
            <link rel="stylesheet"  type="text/css" href="index.css"/>
            <script src="vue.js"></script>
        </head>
        <body>
            <div>
            <h1>--作用域插槽--</h1>
            <div id="example5">
                <current-user>
                    <template v-slot:default="slotProps">
                        {{ slotProps.user.firstName }}
                    </template>
                </current-user>
                <!--独占默认插槽的缩写语法-->
                </br>
                <current-user v-slot="slotProps">
                        {{ slotProps.user.firstName }}
                </current-user>
                <!--后备内容-->
                <current-user></current-user>
            </div>
            <script>
            Vue.component('current-user', {
                data: function () {
                    return {
                        user: {
                            firstName: 'Arya',
                            lastName: 'Stark'
                        }
                    }
                },
                template: '
                    <span>
                        <slot v-bind:user="user">
                            {{ user.lastName }}
                        </slot>
                    </span>
                '
            })
            var example5 = new Vue({
                el:'#example5'
            })
            </script>
            </div>
        </body>
    </html>
  • 相关阅读:
    Vue-发布订阅机制(bus)实现非父子组件的传值
    01. jupyter环境安装
    人工智能
    Javascript
    JavaScript
    MongoDB
    MongoDB
    人工智能
    Flask
    Flask
  • 原文地址:https://www.cnblogs.com/gongshunfeng91/p/11275899.html
Copyright © 2011-2022 走看看