Vue2.0 - 18.2 Vue组件-组件嵌套

vue2.0 基础学习目录

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>18.2.组件嵌套</title>
<script src="../js/vue.js"></script>
<style></style>
</head>
<body>
<!--

-->
<div id="root">
<App></App>
</div>
</body>
<script>
Vue.config.productionTip = false;
const Student = Vue.extend({
name: 'Student',
data() {
return {
stuName: 'odinsam',
stuAge: 20
};
},
template: `
<div style='margin-left:50px;'>
<h2>Student组件</h2>
<span>姓名:{{stuName}}</span>
<span>年龄:{{stuAge}}</span>
</div>
`
});
const School = {
name: 'school',
components: { Student },
data() {
return {
schName: 'vue学校',
schAddress: '南京'
};
},
template: `
<div>
<h2>School组件</h2>
<span>课程:{{schName}}</span>
<span>地址:{{schAddress}}</span>
<div>在校学生</div>
<Student></Student>
</div>
`
};
const Hello = { name: 'Hello', template: `<h2>hello组件</h2>` };
const App = {
name: 'App',
components: { Hello, school: School },
template: `
<div>
<h2>App组件</h2>
<Hello style='margin-left:50px;'></Hello>
<school style='margin-left:50px;'></school>
</div>
`
};
const vm = new Vue({
el: '#root', // 直接指定vue对应的容器
components: {
App
}
});
</script>
</html>

vue2.0 进阶学习的目录

完整代码可以在 GitHub