Why does virtual dom improve performance?

Virtual dom is equivalent to adding a cache between js and real dom. It uses the dom diff algorithm to avoid unnecessary dom operations, thereby improving performance.

Use JavaScript object structure to represent the structure of the DOM tree; then use this tree to build a real DOM tree, insert it into the document, and reconstruct a new object tree when the state changes. Then compare the new tree with the old tree, record the differences between the two trees, and apply the differences recorded in step 2 to the real DOM tree built in step 1, and the view will be updated.

Guess you like

Origin blog.csdn.net/m0_45865109/article/details/125548103