demo代码,不是很理解,先放着
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--view层,模板-->
<div id="app">
<toto>
<toto-title slot="toto-title" :title="title"></toto-title>
<toto-items slot="toto-items" v-for="item in totoItems" :item="item"></toto-items>
</toto>
</div>
<!--1.导入Vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
Vue.component("toto",{
template:
'<div>\
<slot name="toto-title"></slot>\
<ul>\
<slot name="toto-items"></slot>\
</ul>\
</div>'
});
Vue.component("toto-title",{
props: ['title'],
template: '<div>{{title}}</div>'
});
Vue.component("toto-items",{
props: ['item'],
template: '<li>{{item}}</li>'
});
var vm = new Vue({
el: "#app",
data :{
title: "列表",
totoItems: ['狂神说JAVA','狂神说前端','狂神说Linux']
}
});
</script>
</body>
</html>