国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

基于react組件之間的參數(shù)傳遞(詳解)

2019-11-19 15:33:33
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1、父組件向子組件傳遞參數(shù)

class Child extends Component {    componentDidMount(){      let name = this.props.default;      console,log(name);    }    render(){      const { default} = this.props;      return (        <Input />      )   }}
import React, { Component } from 'react';import Child from './Child';class Parent extends Component {  state = {    name: 'Bob'  }  render() {    return (      <div>        <Child default={this.state.name} />      </div>    )  }}

2、子組件向父組件傳遞參數(shù)

class Child extends Component {    state={      name:'Bob'    }    componentDidMount(){      this.props.toParent(this.state.name);    }    render(){      return (        <Input />      )   }}
import React, { Component } from 'react';import Child from './Child';class Parent extends Component {   state = {    name:''  }  getChildInfo = (name)=>{     this.setState({name:name});   }  render() {    return (      <div>        <Child toParent={this.getChildInfo.bind(this)} />      </div>    )  }}

以上這篇基于react組件之間的參數(shù)傳遞(詳解)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江源县| 光泽县| 冀州市| 沁水县| 肥城市| 德阳市| 山阴县| 怀仁县| 永吉县| 栖霞市| 民县| 商水县| 南充市| 麦盖提县| 余姚市| 姜堰市| 准格尔旗| 陕西省| 祥云县| 深圳市| 大安市| 新干县| 若尔盖县| 乌审旗| 莱阳市| 和平县| 大渡口区| 涡阳县| 南城县| 平潭县| 穆棱市| 景谷| 陵川县| 波密县| 海兴县| 简阳市| 理塘县| 丁青县| 类乌齐县| 太白县| 夏津县|