slot插槽
2018-08-03 本文已影响0人
椰果粒
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>插槽</title>
<script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
<div id="app">
<my-content>
<div class="header" slot="header">header</div>
<div class="footer" slot="footer">footer</div>
<my-content/>
</div>
<script>
var myContent = {
template : `<div>
<slot name="header">
<h1>default 插槽</h1>
</slot>
<div class="content">content</div>
<slot name="footer"></slot>
</div>`
}
var vm = new Vue({
el : "#app",
components : {
myContent : myContent
}
})
</script>
</body>
</html>