-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents-basics.html
113 lines (101 loc) · 2.41 KB
/
components-basics.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
111
112
113
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div class="app-1">
<div class="demo">
<button-counter></button-counter>
<button-counter></button-counter>
<button-counter></button-counter>
</div>
<div class="demo">
<div
:style='{fontSize: postFontSize+"em"}'
>
<!-- <blog-post
v-for="post in posts"
:post="post"
:key="post.id"
@enlarge-text='postFontSize+= $event'
>
</blog-post> -->
<blog-post
v-for="post in posts"
:post="post"
:key="post.id"
@enlarge-text='onEnlargetText'
>
</blog-post>
</div>
</div>
<div class="demo">
<custom-input
v-model="searchText"
></custom-input>
<p>{{searchText}}</p>
</div>
<div class="demo">
<alert-box>
something bad happend
</alert-box>
</div>
</div>
<script>
Vue.component('button-counter', {
data: function() {
return {
count: 0
}
},
template: '<button @click="count++">you clicked me {{count}} times.</button>'
});
Vue.component('blog-post', {
props: ['post'],
template: `
<div class="blog-post">
<h3>{{post.title}}</h3>
<button @click='$emit("enlarge-text", 0.1)'>Enlarge text</button>
<div v-html="post.contennt"></div>
</div>
`
});
Vue.component('custom-input', {
props: ['value'],
template: `
<input
:value="value"
@input="$emit('input', $event.target.value)"
>
</input>
`
})
Vue.component('alert-box', {
template: `
<div class="demo-alert-box">
<strong>Error!</strong>
<slot></slot>
</div>
`
})
var app1 = new Vue({
el: '.app-1',
data: {
postFontSize: 1,
posts: [
{id: 1, title:'My journey with Vue', contennt: '...content...'},
{id: 2, title:'Blogging with Vue', contennt: '...content...'},
{id: 1, title:'Why Vue is so fun', contennt: '...content...'},
],
searchText: ''
},
methods: {
onEnlargetText(largeAmount) {
this.postFontSize += largeAmount;
}
}
});
</script>
</body>
</html>