剛接觸react 還不太熟,碰到了一些問題,記錄下
子組件與父組件之間的通訊:
在網(wǎng)站設(shè)計(jì)中,網(wǎng)站頭部可以共用,所以說 就把頭部做成了公共組件,有需要的頁面只需要把組件引入頁面內(nèi)就可以了,而在子組件中需要獲取個(gè)人信息,只要在子組件請(qǐng)求完成后,才能加載父組件中的內(nèi)容:
采用下面寫法?
在子組件中
getMemberInfo = ()=> {
Api.call(apis.detail.getMemberInfo).then(json=> {
if(!json.code){//獲取數(shù)據(jù),復(fù)制操作
}).finally(()=> {//請(qǐng)求完成,發(fā)消息給父組件
this.props.hasloaded &&this.props.hasloaded()
})};
在父組件中? 首先要把子組件引進(jìn)來?jsx中? ??
?import CHeadfrom "../../component/CHead.jsx";
?<Chead hasloaded ={this.hasloaded} />
判斷子組件是否已經(jīng)發(fā)了信息
hasloaded = ()=> {
? ? this.setState({
? ? ? ?cHeadLoaded:true//控制父組件中是否展示內(nèi)容
}, ()=> {
? ? ? //父組件中的數(shù)據(jù)請(qǐng)求
? ? });};
當(dāng)組件傳入的 props 發(fā)生變化時(shí)調(diào)用,例如:父組件狀態(tài)改變,給子組件傳入了新的prop值。用于組件 props 變化后,更新state。
componentWillReceiveProps(nextProps)?
{Logger.info('檢測 props 屬性的改變', nextProps);}
基于react的滾動(dòng)加載組件?
例子地址: https://www.quduopai.cn/
demo:https://pan.baidu.com/s/1dpazka
react中form.create()
在jsx中用form??
寫法
class PwdLoginextends Page{}
const WrappedPwdLogin = Form.create()(PwdLogin);
export default WrappedPwdLogin;//輸出類? export default 用法
參考鏈接 :http://es6.ruanyifeng.com/#docs/module#export-default-??
在父組件中,引入子組件,import PwdLoginfrom './PwdLogin.jsx';
父組件寫法 :class NormalLoginFormextends React.Component{}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(, document.querySelector("#root"));
<div dangerouslySetInnerHTML={{
__html://html代碼<span style=‘color:red’>ddddd</span>,也可以直接插入文字
}}
清空from表單中的數(shù)據(jù)
this.props.form.resetFields();