美文网首页
插槽的使用

插槽的使用

作者: Wo信你个鬼 | 来源:发表于2019-04-11 20:08 被阅读0次
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title></title>
        </head>
        <body>
            <div id="app">
                <tab>
                    <!--具名插槽-->
                    <template v-slot:header>
                        <div>测试</div>
                    </template>
                    <template v-slot:section>
                        <div>插入到了section</div>
                    </template>
                    <!--无名插槽-->
                    <div>我插入footer</div>
                </tab>
            </div>
            <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
            <script type="text/javascript">
                var tab = {
                    template:`
                    <div>
                    //具名插槽
                       <header>
                       <input type="search" placeholder="阿发"/>
                       <slot name="header"></slot>
                       </header>
                       <section>
                       <slot name="section"></slot>
                       </section>
                       
                    //无名插槽   
                       <footer>
                       <slot></slot>
                       </footer>
                    </div>
                    `
                }
                var app = new Vue({
                    el:'#app',  
                    components:{
                        tab
                    }
                })
            </script>
        </body>
    </html>
    
    

    相关文章

      网友评论

          本文标题:插槽的使用

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