-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
inline-template.html
70 lines (68 loc) · 1.73 KB
/
inline-template.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue.js"></script>
</head>
<div id="x">
header
<my-component></my-component>
foot
</div>
<div id="x2">
header
<my-component inline-template>
<div>
<p> These are compiled as the component's own template</p>
<p> Not parent's transclusion content</p>
<p>{{message}}</p>
</div>
</my-component>
foot
</div>
<script>
var xx = new Vue({
el: "#x",
data: {
message: 444,
},
components: {
"my-component": {
data:function () {
return {
message:'100'
}
},
template: `<div>
<p> These are compiled as the component's own template</p>
<p> Not parent's transclusion content</p>
<p> {{message}}</p>
</div>`
}
}
})
//这时可以使用内联模版
var xx = new Vue({
el: "#x2",
data:{
message: 'abc',
},
components: {
"my-component": {
data:function () { //组件只能用返回函数获取值
return {
message:'100'
}
},
template: `<div>
<p> These are compiled as the component's own template</p>
<p> Not parent's transclusion content</p>
<p>{{message}}</p>
</div>`
}
}
})
</script>
</body>
</html>