1 Star 0 Fork 0

will1123/react学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
05在组件中定义局部状态-function.html 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
will1123 提交于 2021-04-22 21:36 . init
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="app"></div>
<!-- react 核心库 -->
<script src="./lib/react.development.js"></script>
<!-- react 浏览器版 -->
<script src="./lib/react-dom.development.js"></script>
<script src="./lib/babel.min.js"></script>
<script type="text/babel">
// 组件,每一个组件都需要返回一个html结构的内容
function App(props) {
// useState 16.8之后新增的 hook 方法
// 可以在function定义的组件中模拟局部状态
// 16.8之后(19年年初)官方推荐function定义组件
// antd从20年后已经全面使用function定义组件结合hook使用
// 接收的参数为初始化的值,返回的数组 第一个参数为 定义的变量名 第二个参数为 修改变量值的方法
const [count, setCount] = React.useState(1);
return <h1 onClick={() => setCount(count + 1)}>当前值为:{count}</h1>;
}
// 父传子 使用props 属性
ReactDOM.render(<App step={2} />, document.getElementById("app"));
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/will1123/react-learning.git
[email protected]:will1123/react-learning.git
will1123
react-learning
react学习
master

搜索帮助