-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08.html
96 lines (92 loc) · 1.98 KB
/
08.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>task-07</title>
<script src="vue/vue.js"></script>
<style>
</style>
</head>
<body>
<div id="app-01">
<anchored-heading :level="1">
hello world
</anchored-heading>
<component-vif :items="items"></component-vif>
<component-vmodel :orivalue="value"></component-vmodel>
</div>
<script>
function getChildrenTextContent(children){
return children.map(function(node){
return node.children?getChildrenTextContent(node.children):node.text
}).join('')
}
Vue.component('component-vif',{
props:["items"],
render:function(createElement){
if(this.items.length){
return createElement('ul',this.items.map(function(item){
return createElement('li',item.name)
}))
} else{
return createElement('p','No items found.')
}
}
})
Vue.component('component-vmodel',{
render:function(createElement){
var self=this
return createElement('p',[
createElement('input',{
domProps:{
value:self.value,
},
on:{
input:function(event){
self.value=event.target.value
}
}
}),
createElement('span',self.value)
])
},
props:['orivalue'],
data:function(){
var value=this.orivalue
return {value}
}
})
Vue.component('anchored-heading',{
render:function(createElement){
var headingId=getChildrenTextContent(this.$slots.default)
.toLowerCase()
.replace(/\W+/g,'-')
.replace(/(^\-|\-$)/g,'')
return createElement(
'h'+this.level,
[
createElement('a',{attrs:{name:headingId,href:'#'+headingId}},this.$slots.default)
]
)
},
props:{
level:{
type:Number,
required:true
}
}
})
var app01=new Vue({
el:'#app-01',
data:{
level:'1',
items:[
{name:'aaa'},
{name:'bbb'}
],
value:''
}
})
</script>
</body>
</html>