-
Notifications
You must be signed in to change notification settings - Fork 0
/
slots.html
110 lines (92 loc) · 2.73 KB
/
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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue Components Slots</title>
<style>
.done {
color: green;
text-decoration: line-through;
}
</style>
</head>
<body>
<div id="app">
<h1>Slots</h1>
<page-layout>
<template #header>
<h1>Here might be a page title</h1>
</template>
<p>A paragraph for the main content</p>
<p>And another one.</p>
<template #footer>
<p>Here's some contact info</p>
</template>
</page-layout>
<todo-item>
Buy Bananas
<template v-slot:description>
<p>Bananas are good and delicious</p>
</template>
<template #button-text>
Make it rain
</template>
</todo-item>
<todo-item>
Buy Bananas
<template v-slot:description>
<p>Bananas are good and delicious</p>
</template>
</todo-item>
</div>
<!-- Development Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<!-- Production Vue.js -->
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script> -->
<script type="text/x-template" id="page-layout-template">
<div class="page-layout-wrap">
<div class="container">
<header>
<slot name="header"></slot>
</header>
<main>
<slot></slot>
</main>
<footer>
<slot name="footer"></slot>
</footer>
</div>
</div>
</script>
<script type="text/x-template" id="todo-item-template">
<div>
<input type="checkbox" v-model="completed">
<span :class="{done: completed}">
<slot></slot>
</span>
<slot name="description"></slot>
<button>
<slot name="button-text">Highlight</slot>
</button>
</div>
</script>
<script>
Vue.component('page-layout', {
template: '#page-layout-template'
})
Vue.component('todo-item', {
template: '#todo-item-template',
data() {
return {
completed: false
}
}
})
new Vue({
el: '#app'
})
</script>
</body>
</html>