-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy path04 child.html
74 lines (66 loc) · 1.98 KB
/
04 child.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
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="vue.js"></script>
<meta charset="UTF-8">
<title>04</title>
</head>
<body>
<pre>
Vue.extend 构造父子组件
</pre>
<div id="app">
<my-component></my-component>
<my-component></my-component>
<my-component></my-component>
</div>
<script>
//*********************************
//* Child
//* 定义:组件 span ,一点点的 data
//**********************************
var Child = Vue.extend({
template: '<span>ABC{{msg}}</span>',
data: function() {
return {
msg: 'EFG'
}
}
})
//*********************************
//* br
//* 定义:组件 html 常用的 <br>,在此
//* 小凡特意当做子组件来使用
//**********************************
var br = Vue.extend({
template:'<br>'
})
//**************************************************************
//* Parent
//* 定义:父组件,使用 br, child
//* 父组件,自已也可以使用 data
//* 跟子组件的data ,可以同名,因为这两个组件是独立的
//* 比如此例:msg,在 Parent, Chile, 都用到了,不互相影响
//**************************************************************
var Parent = Vue.extend({
template: '---Parent:{{msg}}<my-component></my-component>--- <br-component> </br-component>',
components: {
// <my-component> 只能用在父组件模板内
'my-component': Child,
'br-component' : br
},
data :function(){
return {
msg:'台湾小凡'
}
}
})
var vm = new Vue({
el:'#app',
components:{
'my-component': Parent
}
})
</script>
</body>
</html>