https://www.cnblogs.com/vickylinj/p/9578455.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue中的插槽</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="root">
<child>
<p>Dell</p>
<div slot="one">one</div>
<div slot="two">two</div>
</child>
</div>
</body>
<script>
Vue.component('child',{
props:['content'],
//具名插槽 . 指定插入的内容
template:`<div><slot name="one"></slot><div>content</div><slot name="two"></slot></div>`
})
var vm = new Vue({
el:'#root'
})
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="root">
<child>
<!-- 固定写法 -->
<template slot-scope="props">
<li>{{props.item}}---{{props.index}}</li>
</template>
</child>
</div>
</body>
<script>
Vue.component('child',{
data(){
return{
list:[1,2,3,4]
}
},
// 作用域插槽,用于传dom结构 和数据
template:`<div>
<ul>
<slot v-for="(item,index) of list" :item=item :index=index></slot>
</ul>
</div>`
})
var vm = new Vue({
el:'#root'
})
</script>
</html>