-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslot02.html
95 lines (92 loc) · 2.45 KB
/
slot02.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>slot</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<style>
ul {
list-style-type: none;
padding-left: 0;
}
li {
margin-bottom: 5px;
padding-left: 5px;
height: 40px;
line-height: 40px;
border: 1px solid skyblue;
background-color: #ccc;
}
.h {
font-size: 30px;
font-weight: 900;
text-align: center;
}
</style>
</head>
<body>
<div id="app">
<p class="h" v-text="msg"></p>
<parent></parent>
</div>
<!-- 父组件 -->
<template id="p">
<div>
<h1 style="color: red;">我是父组件标题</h1>
<child>
<div slot="top">
<ul>
<li>父组件内容</li>
<li>父组件内容</li>
<li>父组件内容</li>
</ul>
</div>
</child>
</div>
</template>
<!-- 子组件 -->
<template id="s">
<div>
<h2 style="color: blue;">我是子组件内容</h2>
我曾经存在过
<div>
<slot name="top">
<ul>
<li>我曾经存在过---当时明月在,曾照彩云归</li>
<li>我曾经存在过---当时明月在,曾照彩云归</li>
<li>我曾经存在过---当时明月在,曾照彩云归</li>
</ul>
</slot>
<slot name="buttom">
<ul>
<li>我曾经存在过---落花有意随流水,流水无心恋落花</li>
<li>我曾经存在过---落花有意随流水,流水无心恋落花</li>
<li>我曾经存在过---落花有意随流水,流水无心恋落花</li>
</ul>
</slot>
</div>
</div>
</template>
<script>
let child = {
template: '#s',
}
let parent = {
template: '#p',
components: { child },
}
new Vue({
el: '#app',
data: {
msg: '具名插槽--slot',
},
components: {
parent,
child,
},
})
</script>
</body>
</html>