gpt4 book ai didi

reactjs - React JS 中的虚拟 DOM 和真实 DOM 的区别?

转载 作者:行者123 更新时间:2023-12-04 12:44:51 25 4
gpt4 key购买 nike

谁能解释一下 React JS 中虚拟 DOM 和真实 DOM 之间的区别?我得到了以下答案,但我仍然不清楚。任何帮助将不胜感激。

A virtual DOM is a lightweight JavaScript object which originally is just the copy of the real DOM. It is a node tree that lists the elements, their attributes and content as Objects and their properties. React’s render function creates a node tree out of the React components. It then updates this tree in response to the mutations in the data model which is caused by various actions done by the user or by the system.

最佳答案

如果以内部有镜子的电梯为例,则虚拟 DOM 非常容易理解。假设有 4 个人进入电梯。现在,镜子将在 4 个人时反射(reflect)它的外观。再次进入电梯的人会反射镜子的物体。同样的效果发生在人们离开电梯时,镜像对象发生变化(增加、减少甚至空)。所以,现实中的镜子没有真实的物体,而只是通过外在物体来反射(reflect)它的存在。

虚拟 DOM 在概念上是相似的。它没有真正的 DOM。它只是包裹在 JavaScript 对象中的真实 DOM 的副本。每当 DOM 发生变化时,虚拟 DOM 也会发生变化。

为了您的兴趣,您可以看到以下帖子:

Rendered element in react

关于reactjs - React JS 中的虚拟 DOM 和真实 DOM 的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52513283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com