摘要: 当使用component时,父组件的state或prop更新时,无论子组件的state、prop是否更新,都会触发子组件的更新,这会形成很多没必要的render,浪费很多性能;pureComponent的优点在于:pureComponent在shouldComponentUpdate只进行浅层的比较 阅读全文
posted @ 2020-12-13 16:14 panchunxin 阅读(593) 评论(0) 推荐(0)
摘要: 父组件 bindRef (ref) { this.child = ref } clickMethod = () => { this.child.childMethod() } render () { return ( <div className='wrapper'> <p onClick={thi 阅读全文
posted @ 2020-07-15 00:24 panchunxin 阅读(4900) 评论(0) 推荐(0)
摘要: changeDate = () => { const { count } = this.state this.setState({ count: count+1 }) console.log(this.state.count) } render () { const { count } = this 阅读全文
posted @ 2020-06-03 00:15 panchunxin 阅读(464) 评论(0) 推荐(0)
摘要: let bodyEl = document.body let top = 0 function stopBodyScroll (isFixed) { if (isFixed) { top = window.scrollY bodyEl.style.position = 'fixed' bodyEl. 阅读全文
posted @ 2020-03-22 17:38 panchunxin 阅读(285) 评论(0) 推荐(0)
摘要: 方案一: <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> 方案二: document.doc 阅读全文
posted @ 2020-03-22 17:14 panchunxin 阅读(498) 评论(0) 推荐(0)
摘要: 子组件调用父组件的方法,从而改变父组件中state中的值 //父组件 change (value) { console.log(value) this.setState({ red: value.red }) console.log(this.state) } render () { return 阅读全文
posted @ 2020-02-26 23:26 panchunxin 阅读(869) 评论(0) 推荐(0)
摘要: <div className={`title ${index == this.state.index ? 'active' : ''}`}></div> title为固定样式,active为条件渲染 阅读全文
posted @ 2020-02-26 22:51 panchunxin 阅读(1236) 评论(0) 推荐(0)
摘要: react获取dom元素 componentDidMount () { console.log(this.refs.father) } render () { return ( <div> <div ref="father"></div> </div> ) } componentDidMount ( 阅读全文
posted @ 2020-02-23 21:35 panchunxin 阅读(100) 评论(0) 推荐(0)
摘要: class Parent extends Component { handleSth () { console.log('触发父组件成功') } render () { return ( <div> <Child childHandleSth={this.handleSth}></Child> </ 阅读全文
posted @ 2020-02-23 20:38 panchunxin 阅读(474) 评论(0) 推荐(0)
摘要: ifconfig | grep "inet " | grep -v 127.0.0.1 inet后面的就是本机的ip地址 阅读全文
posted @ 2020-02-19 00:19 panchunxin 阅读(2829) 评论(0) 推荐(1)