是的。 React 在虚拟 DOM 模型上工作,并且仅在需要时才会更新真实的浏览器 DOM。 React 中的事件也在虚拟 DOM 上工作,它们被称为合成的 https://facebook.github.io/react/docs/events.html事件。如果您发现出于某种原因需要底层浏览器级事件,只需使用nativeEvent属性即可获取it https://facebook.github.io/react/docs/events.html.
React Virtual DOM 中有一些限制,您可以从中读取here https://facebook.github.io/react/docs/handling-events.html:
Also, this http://reactkungfu.com/2015/10/the-difference-between-virtual-dom-and-dom/可能会有所帮助,并解释了虚拟 DOM 和浏览器 DOM 之间的区别。
浏览器 DOM 只是页面元素的抽象,而 React DOM 将是该抽象的抽象。
The render
的方法ReactDOM
至关重要的是我们如何将 React 元素发送到浏览器 DOM:
var React = require('react');
var ReactDOM = require('react-dom');
var root = React.createElement('div');
ReactDOM.render(root, document.getElementById('example'));
^
|---- Where React elements from React Virtual DOM enter the Browser DOM
在 React 中,我们正在处理 React 元素和 React 组件。
由于 React Element 是 DOM 元素的虚拟表示,因此要处理事件并捕获父元素,您需要通过以下三种方式之一创建 React 组件:
例如,要在单击事件中导航父级,您可以检查以下内容:
var parent = this._reactInternalInstance._currentElement._owner._instance;
REF: React 有没有办法访问父组件实例? https://stackoverflow.com/questions/34257665/is-there-any-way-to-access-the-parent-component-instance-in-react and http://jsfiddle.net/BinaryMuse/j8uaq85e/ http://jsfiddle.net/BinaryMuse/j8uaq85e/