其他分享
首页 > 其他分享> > 8、插槽slot

8、插槽slot

作者:互联网


点击查看代码
<!--view层,模板-->
<div id="app">
    <todo>
    <todo-title slot="todo-title" :title="title"></todo-title>

    <todo-list slot="todo-list" v-for="item in todoList" :list="item"></todo-list>
    </todo>
</div>

<!--    1.导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>

<script>
<!--    slot 插槽-->
    Vue.component("todo",{
        template: '  <div>\
                  <slot name="todo-title"> </slot>\
                    <ul>\
                      <slot name="todo-list"></slot>\
                    </ul>\
                    </div>'
    });

    Vue.component("todo-title",{
        props: ['title'],
        template: '<div>{{title}}</div>'
    });

    Vue.component("todo-list",{
        props: ['list'],
        template: '<li>{{list}}</li>'
    });


    var vm =  new Vue({
        el:"#app",
        data: {
            title: '卿老师学Java',
         todoList: ['狂神说Java','狂神说前端','狂神说Lunix']
        }

    });
</script>

标签:slot,Vue,title,插槽,component,template,狂神,todo
来源: https://www.cnblogs.com/ahhh7931/p/16696857.html