<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>插槽</title>
</head>
<body>
<div id="app">
<shouhe>
<up slot="slot1" :up_value="data_title"></up>
<down slot="slot2" :down_value="book" v-for="book in books"></down>
</shouhe>
</div>
<script src="https://lib.baomitu.com/vue/2.6.11/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
<script>
Vue.component('shouhe', {
template: "<div>" +
"<h1>" +
" <slot name='slot1'></slot>" +
"</h1>" +
"<ul><slot name='slot2'></slot></ul>" +
"</div>"
});
Vue.component('up', {
props: ['up_value'],
template: "<span>{{up_value}}</span>"
})
Vue.component('down', {
props: ['down_value'],
template: "<li>{{down_value}}</li>"
})
var vm = new Vue({
el: "#app",
data: {
data_title: "守鹤爱看的书",
books: ['Java', 'Redis', 'Nginx'],
}
})
</script>
</body>
</html>