- 博客(8)
- 收藏
- 关注
转载 react子组件如何通过父组件传入的函数,将自己的值再传回父组件
class Son extends React.Component { render() { return <input onChange={this.props.onChange}/>; } } class Father extends React.Component { constructor() { super(); this.state ...
2019-01-24 16:39:29 783
转载 react协调算法(页面更新机制)
对比算法:当对比两棵树时,React首先比较两个根节点。根节点的type不同,其行为也不同 1. 不同类型的元素:卸载(销毁旧的节点及状态)旧的元素重建新的元素 <div> <Counter /> </div> <span> <Counter /> </span> 2. 相同类型元素:对比属性,仅更新变...
2019-01-18 16:18:14 796
转载 react中es6的使用
1. class创建组件 class Greeting extends React.Component { render() { return <h1>Hello, {this.props.name}</h1>; } } 2. 声明默认属性 class Greeting extends React.Component { // ... } G...
2019-01-18 15:23:46 2353
原创 受控组件与非受控
受控:通过state与onChange控制 class Form extends Component { constructor() { super(); this.state = { name: '', }; } handleNameChange = (event) => { this.setState({ name: eve...
2019-01-18 11:18:08 658
转载 react中setState的隐患
隐患出处:setState异步更新状态 https://ruby-china.org/topics/32715 https://www.jianshu.com/p/c6257cbef1b1 浅合并(shallow merge):当调用setState修改组件状态时,只需要传入发生改变的State,而不是组件完整的State 如:return {...state, orders: **...
2019-01-17 11:21:23 621
原创 多余文字隐藏,悬浮显示
width: 80%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; &:hover{ overflow: visible; }
2019-01-17 10:12:03 1135
转载 利用react的state机制实现钟表计时器
涉及:state、生命周期钩子 class Clock extends React.Component { constructor(props) { super(props); this.state = {date: new Date()}; } componentDidMount() { this.timerID = setInterval( ...
2019-01-17 10:11:13 1379
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人