插槽
v-slot 定义插槽名
父组件在template中使用插槽
<!--
插槽
20190819
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>插槽</title>
</head>
<body>
<div id='app'>
<child>
<template v-slot:header>
<h1>Header</h1>
</template >
<template v-slot:footer>
<h1>Footer</h1>
</template >
</child>
</div>
</body>
<script src="./js/vue.js"></script>
<script>
Vue.component('child', {
template:`<div>
<slot name='header'></slot>
hello
<slot name='footer'></slot>
</div>`
})
var app = new Vue({
el: '#app',
});
</script>
</html>
作用域插槽
<!--
作用域插槽 列表式样由父组件传入,数据时子组件传递给父组件
20190819
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>插槽</title>
</head>
<body>
<div id='app'>
<child>
<template v-slot:todo = "{props}">
<h1>{{props}}</h1>
</template>
</child>
</div>
</body>
<script src="./js/vue.js"></script>
<script>
Vue.component('child', {
data:function(){
return {
array :[1,2]
}
},
template:`<div>
<ul>
<slot v-for="item of array" name="todo" v-bind:props="item"></slot>
</ul>
</div>`
})
var app = new Vue({
el: '#app',
});
</script>
</html>