-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp_basic.html
53 lines (49 loc) · 1.2 KB
/
comp_basic.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
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Component basic</title>
</head>
<body>
<div id="components-demo">
<button-counter></button-counter>
<button-counter></button-counter>
<button-counter></button-counter>
<hr>
<blog-post
v-for="post in posts"
v-bind:key="post.id"
v-bind:title="post.title"
>
</blog-post>
</div>
<script>
// 定义一个名为 button-counter 的新组件
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
});
// blog-post
Vue.component('blog-post', {
props: ['title'],
template: '<h3>{{ title }}</h3>'
});
var example = new Vue({
el: '#components-demo',
data: {
posts: [
{ id: 1, title: 'My journey with Vue' },
{ id: 2, title: 'Blogging with Vue' },
{ id: 3, title: 'Why Vue is so fun' }
]
}
});
</script>
</body>
</html>