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

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

react 高階組件 怎么獲取子組件的state?

react 高階組件 怎么獲取子組件的state?

http://www.css88.com/react/do...看完官網(wǎng)文檔,大概知道高階組件怎么封裝了。大概知道高階組件怎么封裝了。當(dāng)前的需求是怎么獲取WrappedPage的state?(我們是混合開(kāi)發(fā),需要更新header和右上角的圖標(biāo)!希望在統(tǒng)一的地方處理header和右上角功能;而不是每個(gè)頁(yè)面都去添加重復(fù)代碼。)//basicimportReactfrom'react';importPropTypesfrom'prop-types';//modulesimportupfrom'../modules/cup';//WrappedPage每一個(gè)jsx路由頁(yè)面exportdefaultfunctionmixinsPage(WrappedPage){//……返回另一個(gè)新組件……returnclassPageextendsReact.Component{constructor(props){super(props);}componentWillMount(){console.log(WrappedPage);//清除頁(yè)面右上角的圖標(biāo)up.plugins.setRightButton();}componentDidMount(){console.log(`created=>${this.state.badTitle}`);//設(shè)置titledocument.title=this.state.badTitle;up.plugins.setPageTitle(this.state.badTitle||'');//ios初始化''時(shí)無(wú)效}render(){//……使用最新的數(shù)據(jù)渲染組件//注意此處將已有的props屬性傳遞給原組件return;}}}采用反向繼承模式:可以操作state但是會(huì)導(dǎo)致WrappedPage的componentWillMount和componentWillMount不執(zhí)行了。。。。exportdefaultfunctionmixinsPage(WrappedPage){//……返回另一個(gè)新組件……returnclassPageextendsWrappedPage{constructor(props){super(props);}componentWillMount(){//清除頁(yè)面右上角的圖標(biāo)up.plugins.setRightButton();}componentDidMount(){//設(shè)置titledocument.title=this.state.badTitle;up.plugins.setPageTitle(this.state.badTitle||'');//ios初始化''時(shí)無(wú)效}shouldComponentUpdate(nextProps,nextState){console.log(nextState);}render(){//……使用最新的數(shù)據(jù)渲染組件//注意此處將已有的props屬性傳遞給原組件//return;//使用反向繼承模式:可以操作statereturnsuper.render()}}}以前vueJs的統(tǒng)一處理邏輯!//vueJs的mixinsbeforeCreate(){//清除頁(yè)面右上角的圖標(biāo)plugins.setRightButton();},created(){//log.clearLogs();console.log(`created=>${this.badTitle}`);//設(shè)置titledocument.title=this.badTitle;plugins.setPageTitle(this.badTitle||'');//ios初始化''時(shí)無(wú)效},
查看完整描述

2 回答

?
ABOUTYOU

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

謝邀,使用ref即可。不懂可以翻閱文檔。
//basic
importReactfrom'react';
importPropTypesfrom'prop-types';
//modules
importupfrom'../modules/cup';
//WrappedPage每一個(gè)jsx路由頁(yè)面
exportdefaultfunctionmixinsPage(WrappedPage){
//……返回另一個(gè)新組件……
returnclassPageextendsReact.Component{
constructor(props){
super(props);
+this.WrappedPageRef=React.createRef()
}
componentWillMount(){
console.log(WrappedPage);
//清除頁(yè)面右上角的圖標(biāo)
up.plugins.setRightButton();
}
componentDidMount(){
-console.log(`created=>${this.state.badTitle}`);
//設(shè)置title
-document.title=this.state.badTitle;
-up.plugins.setPageTitle(this.state.badTitle||'');//ios初始化''時(shí)無(wú)效
+if(this.WrappedPageRef.current){
+const{badTitle}=this.WrappedPageRef.current.state
+console.log(`created=>${badTitle}`);
+document.title=badTitle;
+up.plugins.setPageTitle(badTitle||'');//ios初始化''時(shí)無(wú)效
+}
}
render(){
//……使用最新的數(shù)據(jù)渲染組件
//注意此處將已有的props屬性傳遞給原組件
-return;
+return;
}
}
}
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-13
?
慕妹3242003

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

考慮下ref,this.refs.wrappedPage.state這個(gè)就是WrappedPage的state
//basic
importReactfrom'react';
importPropTypesfrom'prop-types';
//modules
importupfrom'../modules/cup';
//WrappedPage每一個(gè)jsx路由頁(yè)面
exportdefaultfunctionmixinsPage(WrappedPage){
//……返回另一個(gè)新組件……
returnclassPageextendsReact.Component{
constructor(props){
super(props);
}
componentWillMount(){
console.log(WrappedPage);
//清除頁(yè)面右上角的圖標(biāo)
up.plugins.setRightButton();
}
componentDidMount(){
console.log(`created=>${this.state.badTitle}`);
//設(shè)置title
document.title=this.state.badTitle;
up.plugins.setPageTitle(this.state.badTitle||'');//ios初始化''時(shí)無(wú)效
}
render(){
//……使用最新的數(shù)據(jù)渲染組件
//注意此處將已有的props屬性傳遞給原組件
return;
}
}
}
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-13
  • 2 回答
  • 0 關(guān)注
  • 2090 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(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)