赞
踩
目录
虚拟 DOM(Virtual DOM),就是一个 JS 对象,用来描述我们希望在页面中看到的 HTML 结构内容.
为什么使用虚拟 DOM? 真实 DOM 对象属性多,处理起来繁琐、效率低。更重要的原因:React 要做跨平台开发,而不是被束缚在浏览器端。
- const element = {
- type: 'h1',
- props: {
- className: 'greeting',
- children: 'Hello JSX!'
- }
- }
-
- // JSX
-
- const d1 = <div></div>
- // 虚拟DOM => { type: 'div' }
- // const divDOM = document.createElement('div')
-
- <div>123</div>
- // 虚拟DOM => { type: 'div', props: { chilren: '123' } }
-
- <div className="tab">123</div>
- // 虚拟DOM => { type: 'div', props: { className: 'tab', chilren: '123' } }

- // JSX
- const el = <div className="abc" onClick={() => {}}>123</div>
-
- // 旧的转化方式:
- // React 元素
- const el = /*#__PURE__*/ React.createElement(
- "div",
- {
- className: "abc",
- onClick: () => {}
- },
- "123"
- );
-
- // 新的转化方式:
- var _jsxRuntime = require("react/jsx-runtime");
- const el = /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
- className: "abc",
- onClick

赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。