What is Virtual DOM?

前端 未结 12 716
遥遥无期
遥遥无期 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:04

    Let's take an example — though a very naive one: If you have something messed up in a room in your home and you need to clean it, what will be your first step? Will you be cleaning your room which is messed up or the whole house? The answer is definitely that you will be cleaning only the room which requires the cleaning. That's what the virtual DOM does.

    Ordinary JS traverses or renders the whole DOM instead of rendering only the part which requires changes.

    So whenever you have any changes, as in you want to add another

    to your DOM then the virtual DOM will be created which actually does not do any changes in the actual DOM. Now with this virtual DOM, you will be checking the difference between this and your current DOM. And only the part which is different (in this case the new
    ) will be added instead of re-rendering the whole DOM.

提交回复
热议问题