-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy path5-6 Authoring Reusable Components .html
116 lines (99 loc) · 2.66 KB
/
5-6 Authoring Reusable Components .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
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="vue.js"></script>
<meta charset="UTF-8">
<title>5-6</title>
<style>
.fade-transition {
transition: opacity .3s ease;
}
.fade-enter,
.fade-leave {
opacity: 0;
}
.box {
width: 250px;
border: 1px solid #9325BC;
padding: 10px;
display: table-cell;
text-align: center;
vertical-align: middle;
}
.box:hover {
-moz-box-shadow: 0 0 10px #ccc;
-webkit-box-shadow: 0 0 10px #ccc;
box-shadow: 0 0 10px #ccc;
border: 10px solid #9325BC;
}
</style>
</head>
<body>
<h3>可重复使用的组件</h3>
<div id="app">
<my-component
:foo="baz"
:bar="qux"
@click="doThis('click')"
@mouseover="onMouseOver('mouseover')">
<img slot="icon" src="http://vuejs.org.cn/images/logo.png" width='200'>
<p slot="main-text">Hello!</p>
</my-component>
<my-component
:foo="baz"
:bar="qux"
@click="doThis('台湾小凡')"
@mouseover="onMouseOver('喜欢 vuejs')">
<img slot="icon" src="http://vuejs.org.cn/images/logo.png" width='200'>
<p slot="main-text">Hello!</p>
</my-component>
<my-component
:foo="baz"
:bar="qux"
@click="doThis('感谢 vue群')"
@mouseover="onMouseOver('Vuejs 364912432')">
<img slot="icon" src="http://vuejs.org.cn/images/logo.png" width='200'>
<p slot="main-text">Hello!</p>
</my-component>
</div>
<br>
<script>
Vue.component('my-component', {
template: `
<div class='box'>
<slot name="icon"></slot>
<slot name="main-text"></slot>
</div>
`,
props: ['foo', 'bar'],
data: function() {
return {
items: {
a: '1', // 子组件的作用域跟父组件的作域是独立不连系
b: '2',
c: '3'
}
}
}
});
new Vue({
el: '#app',
data: {
items: {
'a': '4',
'b': '5',
'c': '6'
}
},
methods: {
'doThis': function(msg) {
console.log(msg);
},
'onMouseOver': function(msg) {
console.log(msg)
}
}
});
</script>
</body>
</html>