第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

怎么傳遞props

怎么傳遞props

翻閱古今 2019-02-02 15:35:42
我在父組件發(fā)送了請(qǐng)求,返回了一些數(shù)據(jù),但是現(xiàn)在子組件收不到數(shù)據(jù),請(qǐng)問(wèn)通過(guò)props怎么傳遞,具體的代碼實(shí)現(xiàn)或是簡(jiǎn)單的案例...... {constructor(props) {    // console.log(props); **這里輸出沒(méi)有得到數(shù)據(jù)thumbnails:{total: 0, url: Array(0)}**    super(props);    this.state = {        thumbnail:[]    };};render() {return (..........componentWillReceiveProps(nextProps){    //debugger    console.log(nextProps);    //沒(méi)有數(shù)據(jù)    this.setState({        thumbnail:nextProps.thumbnail    })
查看完整描述

1 回答

?
素胚勾勒不出你

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊

父組件獲得了數(shù)據(jù)后 將你的數(shù)據(jù)存儲(chǔ)在父組件的state當(dāng)中 ,然后向子組件傳遞通過(guò)state去傳遞就好了

如:



//父組件 Parent

class Parent extends React.Component{

    constructor(props){

        super(props);

        this.state={

            parentDate:""

        }

    }

    handle(){

        //在這里請(qǐng)求拿到數(shù)據(jù)然后進(jìn)行存儲(chǔ)

        this.setState({

            parentDate:"XXXX"

        })

    }

    render(){

        return (

            <Child  parentDate={this.state.parentDate}/>

        )

    }

    //子組件

    class Child extends React.Component{

        constructor(props){

            super(props);

        }

        componentWillReceiveProps(nextProps){

            //在這里可以將接受到的props去存在子組件內(nèi)

        }

        render(){

            return (

                <div>{"I get : "+this.props.parentData}</div>

            )

        }

    }

}


查看完整回答
反對(duì) 回復(fù) 2019-02-13
  • 1 回答
  • 0 關(guān)注
  • 385 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)