-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.组件基础.html
51 lines (51 loc) · 1.22 KB
/
9.组件基础.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>组件基础</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<body>
<div id="app">
<!-- 一定要写成完整的标签,避免<head-comp/> -->
<head-comp></head-comp>
<!-- 属性名attribute会自动转为小写 -->
<body-comp bodycontent="我是身体"></body-comp>
<footer-comp :footercontent="footerContent"></footer-comp>
</div>
</body>
<script type="text/javascript">
//全局组件
Vue.component('headComp',{
//使用函数复制返回数据,否则复用多个组件数据会造成共享
data(){
return {
headTitle:'我是头'
}
},
template:`<h1>{{headTitle}}</h1>`
})
//局部组件
var bodyComp = {
props:['bodycontent'],
template:`<h2>{{bodycontent}}</h2>`
}
var footerComp = {
props:['footercontent'],
template:`<h3>{{footercontent}}</h3>`
}
var vm = new Vue({
el:'#app',
components:{
bodyComp,footerComp
},
//异步加载组件,要点promise,必须要返回一个promise的对象
// conponents:{
// 'my-component': () => import('./my-async-component')
// }
data:{
footerContent:'我是脚'
}
})
</script>
</html>