let vDom = {}; // this is a object that will be used to hold the elements
let d = document.createElement('div');
d.innerHTML = 'hi, i am a new div';
vDom['newDiv'] = d;
在这一点上,我们已经创建了一个Div没有显示在dom,因为它
但是我们可以访问它,添加属性,值,改变等等。
一旦我们调用:(对于ex,将它添加到body)
document.body.appendChild(vDom['newDiv'])
然后我们会看到它;
for one how saw javascript libs come and go , i suggest to any one
to do one simple thing : master JAVAscript, not layers :)
import React, { Component } from 'react'; //You need to do this inside a module to import
class App extends Component{
render(){
return (
<button>Hi</button> //This returns a virtual DOM
)
}
}
return里面的代码实际上是对函数React.createElement的调用:
//render can be rewritten like this:
render(){
return [
React.createElement(
'button',
{
key: null,
ref: null,
},
'Hi',
)
]
}