forked from cassieeric/python_crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtualDOM.html
More file actions
71 lines (60 loc) · 2.01 KB
/
Copy pathvirtualDOM.html
File metadata and controls
71 lines (60 loc) · 2.01 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="root">
<p>韩梅梅的咖啡机</p>
<p>李雷的致富之路</p>
</div>
<script>
class VNode {
constructor( tag, data, value, type ) {
this.tag = tag && tag.toLowerCase();
this.data = data;
this.value = value;
this.type = type;
this.children = [];
}
appChildren( value ) {
this.children.push( value );
}
}
function getVNode( node ) {
let nodeType = node.nodeType;
let _vnode = null;
if ( nodeType === 1 ) {
let nodeName = node.nodeName;
let property = node.attributes;
let _propertyObj = {};
for ( let i = 0; i < property.length; i++ ) {
_propertyObj[ property[i].nodeName ] = property[i].nodeValue;
}
_vnode = new VNode( nodeName, _propertyObj, undefined, nodeType );
let childNodes = node.childNodes;
for( let i = 0; i < childNodes.length; i++ ) {
_vnode.appChildren( getVNode( childNodes[i] ) )
}
} else if ( nodeType === 3 ) {
_vnode = new VNode( undefined, undefined, node.nodeValue, nodeType )
}
return _vnode;
}
function Vue ( options ) {
this._template = document.querySelector( options.el );
let AST = getVNode( this._template )
console.log( AST )
}
const app = new Vue({
el:'#root',
data:{
name:'吴亦凡',
age:22
}
})
</script>
</body>
</html>