-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy path5-5 Components and v-for.html
62 lines (54 loc) · 1.32 KB
/
5-5 Components and v-for.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
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="vue.js"></script>
<meta charset="UTF-8">
<title>5-5</title>
<style>
.fade-transition {
transition: opacity .3s ease;
}
.fade-enter,
.fade-leave {
opacity: 0;
}
</style>
</head>
<body>
<h3>组件和 v-for</h3>
<div id="app">
<!--在父的作用域使用data的 items-->
<my-component v-for="item in items" :str1="item" :index="$index"></my-component>
</div>
<br>
<script>
Vue.component('my-component', {
template: `
<div>
index:{{index}}, props:{{str1}} ,item:{{items.a}}{{items.b}}{{items.c}}
</div>
`,
props: ['str1','index'], // props 来自父组件的 tag 传值
data: function() {
return {
items: {
a: '1', // 子组件的作用域跟父组件的作域是独立不连系
b: '2',
c: '3'
}
}
}
});
new Vue({
el: '#app',
data: {
items: {
'a': '4',
'b': '5',
'c': '6'
}
}
});
</script>
</body>
</html>