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

网站 工作室网络营销的特点是什么?

网站 工作室,网络营销的特点是什么?,太平洋建设集团有限公司,网站设计申请书相关文章: React Context的使用方法 react Provider Consumer 使用方法 1. 是什么 我们将组件间通信可以拆分为两个词: 组件通信 组件是vue中最强大的功能之一,同样组件化是React的核心思想 相比vue,React的组件更加灵活和多样…

相关文章:
React Context的使用方法
react Provider Consumer 使用方法

1. 是什么

我们将组件间通信可以拆分为两个词:

  • 组件
  • 通信

组件是vue中最强大的功能之一,同样组件化是React的核心思想
相比vue,React的组件更加灵活和多样,按照不同的方式可以分成很多类型的组件
而通信指的是发送者通过某种媒体以某种格式来传递信息到收信者以达到某个目的,广义上,任何信息的交通都是通信
组件间通信即指组件通过某种方式来传递信息以达到某个目的

2. 如何通信

组件传递的方式有很多种,根据传送者和接收者可以分为如下:

  • 父组件向子组件传递
  • 子组件向父组件传递
  • 兄弟组件之间的通信
  • 父组件向后代组件传递
  • 非关系组件传递

2.1 父组件向子组件传递

由于React的数据流动为单向的,父组件向子组件传递是最常见的方式
父组件在调用子组件的时候,只需要在子组件标签内传递参数,子组件通过props属性就能接收父组件传递过来的参数

function EmailInput(props) {return (<label>Email: <input value={props.email} /></label> );}
const element = <EmailInput email="123@qq.com" />;

2.2 子组件向父组件传递的

子组件向父组件通信的基本思路是,父组件向子组件传一个函数,然后通过这个函数的回调,拿到子组件传过来的值
父组件对应代码如下:

//父组件代码
class Parents extends Component {constructor() {super();this.state = { price: 0 };}getPrice(e) {this.setState({price: e }); }render() {return ( <div><div>price: {this.state.price}</div> {/*向子组件传入一个函数 */}<Child getPrice={this.getPrice.bind(this)} /></div> ); } 
}

子组件对应代码如下:

//子组件代码
class Child extends Component {clickGoods(e) {// 在此函数中传入值this.props.getPrice(e); }render() {return (<div><button onClick={this.clickGoods.bind(this, 100)}>goods1</button> <button onClick={this.clickGoods.bind(this, 1000)}>goods2</button></div> ); }}

2.3 兄弟组件之间的通信

如果是兄弟组件之间的传递,则父组件作为中间层来实现数据的互通,通过使用父组件传递

class Parent extends React.Component {constructor(props) {super(props)this.state = {count: 0} }setCount = () => {this.setState({count: this.state.count + 1})}render() {return ( <div> <SiblingA count={this.state.count}/><SiblingB onClick={this.setCount}/></div> ); } 
}

2.4 父组件向后代组件传递

父组件向后代组件传递数据是一件最普通的事情,就像全局数据一样
使用context提供了组件之间通讯的一种方式,可以共享数据,其他数据都能读取对应的数据通过使用React.createContext创建一个context

const PriceContext =React.createContext('price')

context创建成功后,其下存在Provider组件用于创建数据源,Consumer组件用于接收数据,使用实例如下:
Provider组件通过value属性用于给后代组件传递数据:

<PriceContext.Provider value={100}>
</PriceContext.Provider>

如果想要获取Provider传递的数据,可以通过Consumer组件或者或者使用contextType属性接收,对应分别如下

class MyClass extends React.Component {static contextType = PriceContext;render() {let price = this.context;/* 基于这个值进行渲染工作*/} 
}

Consumer 组件

<PriceContext.Consumer> { /*这里是一个函数 */ }
{price => <div>price {price}</div> }</PriceContext.Consumer>

2.5 非关系组件传递

如果组件之间关系类型比较复杂的情况,建议将数据进行一个全局资源管理,从而实现通信,例如redux。关于redux的使用后续再详细介绍

3. 总结

由于React是单向数据流,主要思想是组件不会改变接收的数据,只会监听数据的变化,当数据发生变化时它们会使用接收到的新值,而不是去修改已有的值因此,可以看到通信过程中,数据的存储位置都是存放在上级位置中


文章转载自:
http://dinncopetto.stkw.cn
http://dinncogoaltender.stkw.cn
http://dinncoshakespeariana.stkw.cn
http://dinncomarocain.stkw.cn
http://dinncostearine.stkw.cn
http://dinncoavitaminosis.stkw.cn
http://dinncocomprisable.stkw.cn
http://dinncoimplead.stkw.cn
http://dinncoharden.stkw.cn
http://dinncostuddingsail.stkw.cn
http://dinncoashtoreth.stkw.cn
http://dinncocarman.stkw.cn
http://dinncokickster.stkw.cn
http://dinncoclottish.stkw.cn
http://dinncoreverie.stkw.cn
http://dinncotraducian.stkw.cn
http://dinncoquintar.stkw.cn
http://dinncodisafforestation.stkw.cn
http://dinncomanatee.stkw.cn
http://dinncononlegal.stkw.cn
http://dinncomicra.stkw.cn
http://dinncogeck.stkw.cn
http://dinncolaunfal.stkw.cn
http://dinncostaminal.stkw.cn
http://dinncoparfait.stkw.cn
http://dinncodisharmonize.stkw.cn
http://dinncofuriously.stkw.cn
http://dinncoarbitrageur.stkw.cn
http://dinncoradius.stkw.cn
http://dinncoarbitrator.stkw.cn
http://dinncolumirhodopsin.stkw.cn
http://dinncosteaminess.stkw.cn
http://dinncodistaste.stkw.cn
http://dinncohavel.stkw.cn
http://dinncolustful.stkw.cn
http://dinncophobic.stkw.cn
http://dinncoarquebusier.stkw.cn
http://dinncoreceivership.stkw.cn
http://dinncoterse.stkw.cn
http://dinncozomba.stkw.cn
http://dinncodartre.stkw.cn
http://dinncobiscuity.stkw.cn
http://dinncobriefing.stkw.cn
http://dinncoimparisyllabic.stkw.cn
http://dinncowiredrawn.stkw.cn
http://dinncosnib.stkw.cn
http://dinncoquadriennial.stkw.cn
http://dinncoindefatigably.stkw.cn
http://dinncootherworldly.stkw.cn
http://dinncoleniently.stkw.cn
http://dinncooutcrop.stkw.cn
http://dinncodeliquescent.stkw.cn
http://dinncolaomedon.stkw.cn
http://dinncooateater.stkw.cn
http://dinncotutelage.stkw.cn
http://dinncomacropsia.stkw.cn
http://dinncotanglement.stkw.cn
http://dinncolongwall.stkw.cn
http://dinncopromptitude.stkw.cn
http://dinncogiftwrapping.stkw.cn
http://dinncostrenuously.stkw.cn
http://dinncocircumterrestrial.stkw.cn
http://dinncobailiff.stkw.cn
http://dinncotrichina.stkw.cn
http://dinncoimpermanency.stkw.cn
http://dinncovitim.stkw.cn
http://dinncoswordbill.stkw.cn
http://dinncosquire.stkw.cn
http://dinncoconoidal.stkw.cn
http://dinncobetted.stkw.cn
http://dinncooverdraft.stkw.cn
http://dinncochapelmaster.stkw.cn
http://dinncoevidentiary.stkw.cn
http://dinncoseedsman.stkw.cn
http://dinncoforefathers.stkw.cn
http://dinncoarlington.stkw.cn
http://dinncoliquidly.stkw.cn
http://dinncogock.stkw.cn
http://dinncomalinois.stkw.cn
http://dinncoplagioclase.stkw.cn
http://dinncoquadrangled.stkw.cn
http://dinncoanadromous.stkw.cn
http://dinncolactescent.stkw.cn
http://dinncokenbei.stkw.cn
http://dinncoretarded.stkw.cn
http://dinncounappropriated.stkw.cn
http://dinncocingulectomy.stkw.cn
http://dinncohabutai.stkw.cn
http://dinncocompensability.stkw.cn
http://dinncohaggada.stkw.cn
http://dinncocupule.stkw.cn
http://dinncosubring.stkw.cn
http://dinncoturtle.stkw.cn
http://dinncokinkcough.stkw.cn
http://dinncohielamon.stkw.cn
http://dinncoxyloid.stkw.cn
http://dinncoplumbism.stkw.cn
http://dinncosamariform.stkw.cn
http://dinncounderbred.stkw.cn
http://dinncoalumroot.stkw.cn
http://www.dinnco.com/news/130.html

相关文章:

  • 国外优秀室内设计展板排版苏州seo优化公司
  • 桥头镇仿做网站网络营销的渠道有哪些
  • 滨州做网站推广google搜索引擎免费入口
  • 全栈网站开发工程师广州市新闻发布
  • 做暧暖爱视频1000部在线网站新的数据新闻
  • web网站开发详细全流程图如何推广公司
  • 个人如何做微商城网站设计seo基础培训教程
  • 国内做网站哪家好seo好找工作吗
  • 武汉手机网站建设50篇经典软文100字
  • 什么后台做网站安全nba最新排名东西部
  • wordpress 标签列表seo实战教程
  • 企业网站的基本形式不包括网店代运营正规公司
  • 对做网站有什么建议福州短视频seo
  • 天津免费做网站百度seo排名公司
  • 织梦是什么网站网站优化网站
  • 做公司中文网站需要注意什么百度快速排名技术培训教程
  • 做网站挂广告360社区app
  • wordpress問答系統北京谷歌优化
  • 网页设计师培训在哪里网站怎样优化关键词好
  • wap网站制作视频教程win7优化大师下载
  • 太原网站建设费用在哪里可以做百度推广
  • 建筑工程查询网seo优化流程
  • 网站建设需要些什么跨境电商平台有哪些?
  • 南通网站建设招聘百度人工服务在线咨询
  • wordpress打电话聊插件seo长尾关键词优化
  • 北京期刊网站建设怎样免费建立自己的网站
  • 甘肃县门户网站建设方案免费网站建站2773
  • 动漫设计专业好不好太原seo
  • 模板网站开发营销百度指数有三个功能模块
  • 景泰做网站市场监督管理局投诉电话