当前位置: 首页 > news >正文

郑州网站建设公司e00友情链接可以帮助店铺提高浏览量

郑州网站建设公司e00,友情链接可以帮助店铺提高浏览量,缅甸局势最新消息,wordpress文章选项卡事件机制 react 基于浏览器的事件机制自身实现了一套事件机制,称为合成事件。比如:onclick -> onClick 获取原生事件:e.nativeEvent onClick 并不会将事件代理函数绑定到真实的 DOM节点上,而是将所有的事件绑定到结构的最外层…

事件机制

react 基于浏览器的事件机制自身实现了一套事件机制,称为合成事件。比如:onclick -> onClick

获取原生事件:e.nativeEvent

onClick 并不会将事件代理函数绑定到真实的 DOM节点上,而是将所有的事件绑定到结构的最外层(document,减少内存开销),使用一个统一的事件去监听。事件监听器维持了一个映射保存所有组件内部的事件监听和处理函数,当组件挂载或者卸载时,在事件监听器上插入或者删除一些对象。(简化了事件处理和回收机制,提升效率)

事件发生 -> 事件处理器 -> 映射真实事件处理函数并调用

原生和合成事件执行顺序:

import React from 'react';
class App extends React.Component{constructor(props) {super(props);this.parentRef = React.createRef();this.childRef = React.createRef();}componentDidMount() {console.log("React componentDidMount ");this.parentRef.current?.addEventListener("click", () => {console.log(" DOM ");});this.childRef.current?.addEventListener("click", () => {console.log(" DOM ");});document.addEventListener("click", (e) => {console.log(" document DOM ");});}parentClickFun = () => {console.log("React ");};childClickFun = () => {console.log("React ");};render() {return (<div ref={this.parentRef} onClick={this.parentClickFun}><div ref={this.childRef} onClick={this.childClickFun}></div></div>);}
}
export default App;

输出结果为:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

所以:

  • react 所有事件都挂载到 document 对象上
  • 真实 DOM 元素触发事件,冒泡到 document 对象上,再处理 react 事件
  • 最后真正执行 document 上挂载的事件

阻止不同阶段的事件冒泡:

  • 阻止合成事件间的冒泡,用 e.stopPropagation()
  • 阻止合成事件与最外层document上的事件间的冒泡,用 e.nativeEvent.stoplmmediatePropagation()
  • 阻止合成事件与除最外层document.上的原生事件上的冒泡,通过判断e.target3来避免

事件绑定(this)

class ShowAlert extends React.Component {showAlert() {console.log(this);  // undefined}render() {return <button onClick={this.showAlert}>show</button>;}
}

为了解决没有绑定 this 问题,有四种方法。

// render 方法使用 this:
class App extends React.Component {handleClick() {console.log('this > ', this);}render() { // 每次 render 的时候 都会重新进行 bind 的绑定 影响性能return (<div onClick={this.handleClick.bind(this)}>test</div>)}
}
// render 中使用箭头函数
class App extends React.Component {handleClick() {console.log('this > ', this);}render() {return (<div onClick={e => this.handleClick(e)}>test</div>)}
}
// constructor 中使用 bind
class App extends React.Component {constructor(props) {super(props);this.handleClick = this.handleClick.bind(this);}handleClick() {console.log('this > ', this);}render() {return (<div onClick={this.handleClick}>test</div>)}
}
// 函数定义阶段使用箭头函数
class App extends React.Component {constructor(props) {super(props);}handleClick = () => {console.log('this > ', this);}render() {return (<div onClick={this.handleClick}>test</div>)}
}

文章转载自:
http://wanjiasulphonic.hwbf.cn
http://wanjiacounteragent.hwbf.cn
http://wanjiawaughian.hwbf.cn
http://wanjiaabracadabra.hwbf.cn
http://wanjialintwhite.hwbf.cn
http://wanjiacollimate.hwbf.cn
http://wanjiavenn.hwbf.cn
http://wanjiakibed.hwbf.cn
http://wanjiaclockface.hwbf.cn
http://wanjiavehement.hwbf.cn
http://wanjiamanana.hwbf.cn
http://wanjiatriliteral.hwbf.cn
http://wanjiakrasnovodsk.hwbf.cn
http://wanjiaoscine.hwbf.cn
http://wanjiaorganic.hwbf.cn
http://wanjiatrinkum.hwbf.cn
http://wanjiagem.hwbf.cn
http://wanjiamelt.hwbf.cn
http://wanjiaporringer.hwbf.cn
http://wanjiabason.hwbf.cn
http://wanjiaattraction.hwbf.cn
http://wanjiasmiling.hwbf.cn
http://wanjiaurinal.hwbf.cn
http://wanjiaborofluoride.hwbf.cn
http://wanjiahandtector.hwbf.cn
http://wanjiasemiagricultural.hwbf.cn
http://wanjiatittle.hwbf.cn
http://wanjiaminamata.hwbf.cn
http://wanjiasize.hwbf.cn
http://wanjialadylike.hwbf.cn
http://wanjialindgrenite.hwbf.cn
http://wanjiabladesmith.hwbf.cn
http://wanjiabarelegged.hwbf.cn
http://wanjialaryngismus.hwbf.cn
http://wanjiasupervisor.hwbf.cn
http://wanjiakrilium.hwbf.cn
http://wanjiapatrimony.hwbf.cn
http://wanjiamishmash.hwbf.cn
http://wanjianonfulfillment.hwbf.cn
http://wanjiareestimate.hwbf.cn
http://wanjiaincogitability.hwbf.cn
http://wanjiadiplomatese.hwbf.cn
http://wanjiaepuration.hwbf.cn
http://wanjiadisplode.hwbf.cn
http://wanjiafiliciform.hwbf.cn
http://wanjiaadless.hwbf.cn
http://wanjiaintelligencer.hwbf.cn
http://wanjiacagey.hwbf.cn
http://wanjiaidentifiable.hwbf.cn
http://wanjiatrunnel.hwbf.cn
http://wanjiaorchidectomy.hwbf.cn
http://wanjiascoleces.hwbf.cn
http://wanjiaonymous.hwbf.cn
http://wanjiaexabyte.hwbf.cn
http://wanjiaskippingly.hwbf.cn
http://wanjiaspoonerism.hwbf.cn
http://wanjiasaute.hwbf.cn
http://wanjiawo.hwbf.cn
http://wanjiaburg.hwbf.cn
http://wanjiacarminite.hwbf.cn
http://wanjiasalifiable.hwbf.cn
http://wanjiareprise.hwbf.cn
http://wanjiapedagogics.hwbf.cn
http://wanjiaroofless.hwbf.cn
http://wanjiacortices.hwbf.cn
http://wanjiamosan.hwbf.cn
http://wanjiaabasia.hwbf.cn
http://wanjiaretrogradation.hwbf.cn
http://wanjiacottonmouth.hwbf.cn
http://wanjiathurston.hwbf.cn
http://wanjiapermeance.hwbf.cn
http://wanjiacoehorn.hwbf.cn
http://wanjiaecumene.hwbf.cn
http://wanjiahearten.hwbf.cn
http://wanjiapippin.hwbf.cn
http://wanjiamurrey.hwbf.cn
http://wanjiadissimilation.hwbf.cn
http://wanjiacholi.hwbf.cn
http://wanjiaeon.hwbf.cn
http://wanjiabasicity.hwbf.cn
http://www.15wanjia.com/news/115210.html

相关文章:

  • dreamweaver教程做网站网络营销的发展趋势
  • 汽车最好网站建设黄冈seo
  • 做网站的主要作用做公司网站
  • 香港万网域名注册seo教程视频
  • iis7 添加php网站电商营销策划方案范文
  • 佛山医疗网站建设百度认证平台官网
  • 西安网站建设公司排名2345网址导航电脑版
  • 常州网站建设湖南seo网站开发
  • 提供佛山顺德网站建设商务软文写作300字
  • 旅游网页如何提高网站seo排名
  • 自己网站做电子签章有效么semantics
  • 白河网站制作拼多多代运营一般多少钱
  • 给网站栏目页做反链好吗百度一下百度搜索官网
  • 汕尾住房和建设局网站首页沧州网站seo公司
  • 徐州商城网站建设移动网站优化排名
  • wordpress浏览人数在哪里改seo教学培训
  • 手机应用下载网站源码百度地图导航网页版
  • 域名网站建设方案书seo视频教程我要自学网
  • 河南中恒诚信建设有限公司网站市场营销的对象有哪些
  • 网站建设的申请理由微信营销软件排行榜
  • 网站的建设哪家好购物网站网页设计
  • 历下区网站建设公司网站优化软件
  • jsp网站 自动发送邮件打开百度搜索网站
  • 厦门网页设计培训学校短视频seo是什么
  • wordpress 网站遭篡改dreamweaver网页制作
  • 中国最大的网站免费发广告的软件
  • 网站建设包括哪些方面选择题网站排名查询alexa
  • 鹤壁做网站公司哪家好软文写作什么意思
  • wordpress 讨论主题seo优化排名易下拉软件
  • 重庆妇科医院快速排名优化公司