-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path34.组件间插槽——具名slots.html
61 lines (57 loc) · 1.25 KB
/
34.组件间插槽——具名slots.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!--
<slot> 元素可以用一个特殊的属性 name 来配置如何分发内容
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> 具名Slots </title>
<script type="text/javascript"src="vue.js"></script>
</head>
<body>
<div id="main">
<my-component>
<h1 slot="header">Title</h1>
<p>Main content</p>
<p>Something else</p>
<p slot="footer">Some info</p>
</my-component>
<!-- 以上将被渲染成
<div class="container">
<header>
<h1>Title</h1>
</header>
<main>
<p>Main content</p>
<p>Something else</p>
</main>
<footer>
<p>Some info</p>
</footer>
</div>
-->
</div>
</body>
<script type="text/javascript">
Vue.component('my-component', {
template: `
<div class="container">
<header>
<slot name="header"></slot>
</header>
<main>
<slot></slot>
</main>
<footer>
<slot name="footer"></slot>
</footer>
</div>
`,
})
new Vue({
el: '#main',
data: {
}
})
</script>
</html>