
React
zdw火车叨位去
转前端中,待续。。。
展开
-
React:生命周期(新)
1.新版去掉了原来的componentWillMount,componentWillUpdate,componentWillReceiveProps。 2.新增函数 getDerivedStateFromProps 控制state的值在任何时候都取决于props 返回值为null或state对象,不能为undefined 原型对象自身静态函数,使用前要加static static getDerivedStateFromProps(props,state)...原创 2021-03-13 20:40:37 · 210 阅读 · 0 评论 -
React:生命周期(旧)
1.setState()不能写在render()内。 2.setInterval()等函数不能随意写在class内render外。 3.对象key与value相同会触发简写机制。{opacity:opacity}等同于{opacity} 4.生命周期函数无需写成箭头函数形式。 class Life extends React.Component{ state={opacity:1} render(){ return (<div> <h1 style..原创 2021-03-13 17:27:23 · 104 阅读 · 0 评论 -
React:refs
1.refs字符串形式(官方不推荐) class Demo extends React.Component{ render(){ return(<div> <input ref='input1' type="text"placeholder="点击按钮提示数据" /> <button onClick={this.showData}>按钮</button> <input onBlur={this.blurData} ref=原创 2021-03-11 21:17:18 · 88 阅读 · 0 评论 -
React:props
1.通过标签属性从组件外向组件内传递变化的数据。 2.组件标签的所有属性都保存在props中。 3.每个组件对象都会有props(properties)属性。 4.props只读,组件内部不要修改props数据。 5.用解构赋值批量传输属性:{...P} 展开运算符不能展开对象 由于React和jsx,导致可以在标签属性传递时展开对象 6.js代码必须写在{ }中。 age={18} 7.限制传递的props:对组件标签属性进行限制 限制语句如果写在class外面,要写类名 Person.原创 2021-03-11 18:42:39 · 134 阅读 · 0 评论