forked from jigneshbhimani/VueJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6Composition.txt
157 lines (106 loc) · 3.08 KB
/
6Composition.txt
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
Composing with components in Vue Js
- what is component
- make Home component
- make child component for Home component
1) Make first Home component:
- src/components/Home.vue:
<template>
<div>
<h1>Home Component</h1>
</div>
</template>
<script>
export default {
name: 'Home',
}
</script>
<style scoped>
div{
background-color: #dde5ec;
height: 500px;
}
</style>
2) Import Home component in App.vue:
- src/App.vue:
<template>
<div id="app">
<Home /> // Use Home component
</div>
</template>
<script>
import Home from "./components/Home.vue"; // import Home component
export default {
name: "App",
components: {
Home, // export Home component
},
};
</script>
3) Make second Users component:
- src/components/Users.vue:
<template>
<div class="users">
<h1>Users Component</h1>
</div>
</template>
<script>
export default {
name: 'Users',
}
</script>
<style scoped>
.users{
background-color: antiquewhite;
width: 300px;
height: 100px;
padding: 42px;
margin: 20px;
}
</style>
4) Make thrid Products component:
- src/components/Products.vue:
<template>
<div class="users">
<h1>Products Component</h1>
</div>
</template>
<script>
export default {
name: 'Products',
}
</script>
<style scoped>
.users{
background-color: antiquewhite;
width: 300px;
height: 100px;
padding: 42px;
margin: 20px;
}
</style>
5) User component and Products component import in Home component:
- src/components/Home.vue:
<template>
<div>
<h1>Home Component</h1>
<Users /> // use Users component
<Products /> // use Products component
</div>
</template>
<script>
import Users from "./Users.vue"; // import Home component
import Products form "./Products.vue"; // import Products component
export default {
name: 'Home',
components:{
Users, // export Users component
Products, // export Products component
}
}
</script>
<style scoped>
div{
background-color: #dde5ec;
height: 500px;
}
</style>