From 591b3eaafa7e9733565a9fc962d19aba816e6b1c Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 23 Oct 2024 19:33:04 +0800 Subject: [PATCH] =?UTF-8?q?2.=20=E4=BA=8B=E4=BB=B6=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 128 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 51 deletions(-) diff --git a/src/App.js b/src/App.js index fb90132..5d2ab59 100644 --- a/src/App.js +++ b/src/App.js @@ -3,71 +3,97 @@ import React from "react"; import './App.css'; function App() { - // vue3 组合式 API - // React 必须大写 Pascal 命名 组件 - function FnHello({name="Fn"}){ - return
Hello world By {name}
- } - - let com = FnHello({name:"obj"}) - - function FnHello2(){ - return React.createElement("div", [], "Hello world By React.createElement") - } - - // vue2 选项式 API - class ClassHello extends React.Component { - // eslint-disable-next-line no-useless-constructor - constructor(props) { - super(props); + // vue3 组合式 API + // React 必须大写 Pascal 命名 组件 + function FnHello({name = "Fn"}) { + return
Hello world By {name}
} - render() { - return
Hello world By Class
+ let com = FnHello({name: "obj"}) + + function FnHello2() { + return React.createElement("div", [], "Hello world By React.createElement") } - } - // React 不能直接渲染 js 对象 - let obj = { - a: 1, - b: 2 - } + // vue2 选项式 API + class ClassHello extends React.Component { + // eslint-disable-next-line no-useless-constructor + constructor(props) { + super(props); + } - // 如果是数组则依次遍历 - let arr1 = [ - 1, - 2, - 3 - ] + render() { + return
Hello world By Class
+ } + } - let arr2 = [ - FnHello({name:"arr1"}), - FnHello({name:"arr2"}), - FnHello({name:"arr3"}), - ] + // React 不能直接渲染 js 对象 + let obj = { + a: 1, + b: 2 + } - return ( -
-
- {/*logo*/} - + // 如果是数组则依次遍历 + let arr1 = [ + 1, + 2, + 3 + ] - + let arr2 = [ + FnHello({name: "item1"}), + FnHello({name: "item2"}), + FnHello({name: "item3"}), + ] - + function clickHandler2() { + console.log("按钮2被点击") + } - {com} + function clickHandler3(arg, e) { + console.log("按钮3被点击, 参数 " + arg) + console.log("合成的事件对象", e) + // 阻止事件冒泡 + e.stopPropagation() + } - {JSON.stringify(obj)} + return ( +
+
+ {/*logo*/} + -
+ - {arr1} + - {arr2} -
-
- ); + {com} + + {JSON.stringify(obj)} + +
+ + {arr1} + + {arr2} + + +
+ {/*事件绑定*/} + + + +
+
+ + +
+
+
+ ); } export default App;