<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>插槽</title>
</head>
<body>
<div id="app">
{{message}}
<todo>
<totitle slot="totitle" :titile="titile"> </totitle>
<toul slot="toul" v-for="i in list" :list="i"></toul>
</todo>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
Vue.component("todo",{
template:'<div> \
<slot name="totitle"> </slot> \
<ul> </ul> \
<slot name="toul"> </slot> \
</div>'
});
Vue.component("totitle",{
props:['titile'],
template:'<div>{{titile}} </div>'
})
Vue.component("toul",{
props:["list"],
template:"<li>{{list}} </li>"
})
let vm= new Vue({
el:"#app",
data:{
titile:"标题",
message:"goodjob",
list:["houge","fenxiang","jiangshi","jianxingziji"]
}
})
</script>
</body>
</html>
|