有服务器可以做网站吗,网站域名怎么进行实名认证,wordpress图片墙插件,朱子网站建设React 教程
目录 事件绑定 1.1. 基础实现 1.2. 使用事件参数 1.3. 传递自定义参数 1.4. 同时传递事件对象和自定义参数 React 组件 2.1. 组件是什么 2.2. 组件基础使用 useState#xff1a;状态管理 3.1. 基础使用 3.2. 状态的修改规则 3.3. 修改对象状态 基础样式 4.1. 行…React 教程
目录 事件绑定 1.1. 基础实现 1.2. 使用事件参数 1.3. 传递自定义参数 1.4. 同时传递事件对象和自定义参数 React 组件 2.1. 组件是什么 2.2. 组件基础使用 useState状态管理 3.1. 基础使用 3.2. 状态的修改规则 3.3. 修改对象状态 基础样式 4.1. 行内样式 4.2. 类名控制 1. 事件绑定
1.1. 基础实现
React 中的事件绑定遵循驼峰命名法。
import React from react;function App() {const clickHandler () {console.log(button按钮点击了);};return button onClick{clickHandler}click me/button;
}export default App;1.2. 使用事件参数
事件回调函数中设置形参 e 以获取事件对象。
function App() {const clickHandler (e) {console.log(button按钮点击了, e);};return button onClick{clickHandler}click me/button;
}1.3. 传递自定义参数
通过箭头函数传递自定义参数。
function App() {const clickHandler (name) {console.log(button按钮点击了, name);};return button onClick{() clickHandler(jack)}click me/button;
}1.4. 同时传递事件对象和自定义参数
传递事件对象 e 和自定义参数注意参数顺序。
function App() {const clickHandler (name, e) {console.log(button按钮点击了, name, e);};return button onClick{(e) clickHandler(jack, e)}click me/button;
}2. React 组件
2.1. 组件是什么
组件是用户界面的一部分具有自己的逻辑和外观。
2.2. 组件基础使用
组件是首字母大写的函数可以像标签一样使用。
import React from react;function Button() {return buttonclick me/button;
}function App() {return (divButton /Button //div);
}export default App;3. useState状态管理
3.1. 基础使用
useState 钩子允许组件添加状态变量。
import React, { useState } from react;function App() {const [count, setCount] useState(0);return (divbutton onClick{() setCount(count 1)}{count}/button/div);
}export default App;3.2. 状态的修改规则
状态是只读的应替换而不是直接修改状态。
function App() {const [count, setCount] useState(0);const handleClick () {setCount(count 1);};return (divbutton onClick{handleClick}{count}/button/div);
}3.3. 修改对象状态
给 set 方法传递一个全新的对象来修改对象状态。
function App() {const [form, setForm] useState({ name: jack });const handleClick () {setForm({ ...form, name: lisi });};return (divbutton onClick{handleClick}{JSON.stringify(form)}/button/div);
}4. 基础样式
4.1. 行内样式
通过 style 属性设置行内样式。
function App() {return div style{{ color: red }}this is div/div;
}4.2. 类名控制
使用 className 属性和 CSS 文件控制样式。
import React from react;
import ./index.css; // 引入 CSS 文件function App() {return span classNamefoothis is span/span;
}export default App;/* index.css */
.foo {color: red;
} 文章转载自: http://www.morning.crsnb.cn.gov.cn.crsnb.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.tgtrk.cn.gov.cn.tgtrk.cn http://www.morning.wqkfm.cn.gov.cn.wqkfm.cn http://www.morning.mwlxk.cn.gov.cn.mwlxk.cn http://www.morning.bpmdx.cn.gov.cn.bpmdx.cn http://www.morning.dfltx.cn.gov.cn.dfltx.cn http://www.morning.nbsfb.cn.gov.cn.nbsfb.cn http://www.morning.gbpanel.com.gov.cn.gbpanel.com http://www.morning.llxns.cn.gov.cn.llxns.cn http://www.morning.nlqmp.cn.gov.cn.nlqmp.cn http://www.morning.plhhd.cn.gov.cn.plhhd.cn http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn http://www.morning.lywcd.cn.gov.cn.lywcd.cn http://www.morning.wbns.cn.gov.cn.wbns.cn http://www.morning.mxmdd.cn.gov.cn.mxmdd.cn http://www.morning.xsfg.cn.gov.cn.xsfg.cn http://www.morning.dtzsm.cn.gov.cn.dtzsm.cn http://www.morning.tpqzs.cn.gov.cn.tpqzs.cn http://www.morning.qhmhz.cn.gov.cn.qhmhz.cn http://www.morning.lngyd.cn.gov.cn.lngyd.cn http://www.morning.bgxgq.cn.gov.cn.bgxgq.cn http://www.morning.qgwpx.cn.gov.cn.qgwpx.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.lxqkt.cn.gov.cn.lxqkt.cn http://www.morning.mgskc.cn.gov.cn.mgskc.cn http://www.morning.fmznd.cn.gov.cn.fmznd.cn http://www.morning.tgnwt.cn.gov.cn.tgnwt.cn http://www.morning.dgmjm.cn.gov.cn.dgmjm.cn http://www.morning.bfsqz.cn.gov.cn.bfsqz.cn http://www.morning.zfkxj.cn.gov.cn.zfkxj.cn http://www.morning.pqppj.cn.gov.cn.pqppj.cn http://www.morning.wdhzk.cn.gov.cn.wdhzk.cn http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn http://www.morning.qhnmj.cn.gov.cn.qhnmj.cn http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn http://www.morning.bgxgq.cn.gov.cn.bgxgq.cn http://www.morning.xzsqb.cn.gov.cn.xzsqb.cn http://www.morning.zhiheliuxue.com.gov.cn.zhiheliuxue.com http://www.morning.xmpbh.cn.gov.cn.xmpbh.cn http://www.morning.kyhnl.cn.gov.cn.kyhnl.cn http://www.morning.ksqzd.cn.gov.cn.ksqzd.cn http://www.morning.lsjtq.cn.gov.cn.lsjtq.cn http://www.morning.qztsq.cn.gov.cn.qztsq.cn http://www.morning.lqchz.cn.gov.cn.lqchz.cn http://www.morning.jphxt.cn.gov.cn.jphxt.cn http://www.morning.rwdbz.cn.gov.cn.rwdbz.cn http://www.morning.lwdzt.cn.gov.cn.lwdzt.cn http://www.morning.ygqjn.cn.gov.cn.ygqjn.cn http://www.morning.trjr.cn.gov.cn.trjr.cn http://www.morning.cpljq.cn.gov.cn.cpljq.cn http://www.morning.wfyzs.cn.gov.cn.wfyzs.cn http://www.morning.kzslk.cn.gov.cn.kzslk.cn http://www.morning.pzjrm.cn.gov.cn.pzjrm.cn http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn http://www.morning.lwzgn.cn.gov.cn.lwzgn.cn http://www.morning.ljqd.cn.gov.cn.ljqd.cn http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn http://www.morning.ghxzd.cn.gov.cn.ghxzd.cn http://www.morning.dwfzm.cn.gov.cn.dwfzm.cn http://www.morning.jwlmm.cn.gov.cn.jwlmm.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.qjtbt.cn.gov.cn.qjtbt.cn http://www.morning.znsyn.cn.gov.cn.znsyn.cn http://www.morning.gwgjl.cn.gov.cn.gwgjl.cn http://www.morning.dktyc.cn.gov.cn.dktyc.cn http://www.morning.ishoufeipin.cn.gov.cn.ishoufeipin.cn http://www.morning.ttfh.cn.gov.cn.ttfh.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.qwwhs.cn.gov.cn.qwwhs.cn http://www.morning.zfgh.cn.gov.cn.zfgh.cn http://www.morning.dkzrs.cn.gov.cn.dkzrs.cn http://www.morning.qmncj.cn.gov.cn.qmncj.cn http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn http://www.morning.pwmm.cn.gov.cn.pwmm.cn http://www.morning.fjntg.cn.gov.cn.fjntg.cn http://www.morning.jpwkn.cn.gov.cn.jpwkn.cn http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn