What is Virtual DOM?

前端 未结 12 701
遥遥无期
遥遥无期 2020-11-28 01:39

Recently, I looked at Facebook\'s React framework. It uses a concept called \"the Virtual DOM,\" which I didn\'t really understand.

What is the Virtual DOM? What are

12条回答
  •  再見小時候
    2020-11-28 02:22

    let's make order and sense in this matter. React (or any other library) are a "layer" on javascript.

    There is no such thing as virtual dom, there is unattached dom .

    let me explain in simple javascript :

     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;
    

    at this point we have created a Div which is not shown on the dom , because it has not attached

    but we can access it, add attributes, values, change etc..

    once we call : (for ex,add it to body)

        document.body.appendChild(vDom['newDiv'])
    

    then we will see it;

     for one how saw javascript libs come and go , i suggest to any one 
     to do one simple thing : master JAVAscript, not layers :)
    

提交回复
热议问题