插槽
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<todo>
<todo-title slot="todo-title" v-bind:name1="title"></todo-title>
<todo-items slot="todo-items" v-for="item in todoItems" v-bind:item1="item"></todo-items>
</todo>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
<!-- 通过name属性绑定-->
Vue.component("todo",{
template: '<div>\
<slot name="todo-title"></slot>\
<ul>\
<slot name="todo-items"></slot>\
</ul>\
</div>'
});
Vue.component("todo-title",{
props:["name1"],
template:'<div>{{name1}}</div>'
});
Vue.component("todo-items",{
props: ["item1"],
template:"<li>{{item1}}</li>"
});
var vm = new Vue({
el: "#app",
data: {
title: "图书馆系列图书",
todoItems: ['三国演义', '红楼梦', '西游记', '水浒传']
}
});
</script>
</body>
</html>