-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2demo.html
103 lines (81 loc) · 2.29 KB
/
2demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue 2demo</title>
<script src="./js/vue.js"></script>
</head>
<body>
<div id="app">
<my-header></my-header>
</div>
<div id="app2">
<my-header></my-header>
</div>
<div id="app3">
<my-header></my-header>
<my-header></my-header>
</div>
<div id="app4">{{ message }}</div>
<script>
// 全局组件
Vue.component("my-header", {
template: "<h2>标题</h2>"
})
var vm = new Vue({
el:"#app",
});
var vm2 = new Vue({
el:"#app2",
});
var data = {
count: 0
}
// 局部组件
var vm3= new Vue({
el:"#app3",
data: {
message:"hello vue3!!!"
},
components: {
"my-header": {
template: "<h2 @click='changeCount'>标题3 {{ count }} </h2>",
data: function() {
// 局部组件数据是不能全局共享的,因此采用函数返回数据的方式
// return {
// message:"局部 hello vue3!!!"
// }
// return data;// 这样会影响到全局数据,两个组件的 count 同时增加
return {
count: 0
}
},
methods: {
changeCount: function() {
this.count++
}
},
}
}
})
// vue 组件其实是一个可扩展的 Vue 实例
// Vue.extend({
// })
// var vm4 = new Vue({
// el: "app4",
// template: "<h1>app应用</h1>"
// })
var myComponent = Vue.extend({
data: function() {
return {
message: "hello vue 4!!!"
}
}
})
var _vm4 = new myComponent({
el: "#app4"
})
</script>
</body>
</html>