React Reflux Store获取state值 Data Flow
// Component class Plans extends React.Component { constructor(props){ super(props); this.state = { params: props.params }; } render() { return ( <div className="plan-list-container"> <PlanList { ...this.state } /> </div> ); } }
// PlanList Component class PlanList extends React.Component { constructor(props){ super(props); this.state = { page_loading: false }; PlanActions.setParams(props.params); }
// PlanActions var PlanActions = Reflux.createActions([ 'setParams', 'loadPlans', 'loadPlansSuccess' ]); PlanActions.loadPlans.preEmit = function(){ PlanActions.loadPlansSuccess(); };
// Store var PlanStore = Reflux.createStore({ init() { this.listenToMany(PlanActions); }, setParams(params) { this.params = params; }, loadPlans() { this.trigger({ loading: true }); }, loadPlansSuccess() { $.ajax({ url: this.ajaxApi, dataType: 'json', data: { sku: this.params.sku }, cache: true, success: function(data) {
有疑问或技术交流,扫描公众号一起讨论学习。
更多React在线学习访问:http://each.sinaapp.com/react/index.html
相关推荐
游走的豚鼠君 2020-11-10
81417707 2020-10-30
ctg 2020-10-14
小飞侠V 2020-09-25
PncLogon 2020-09-24
jipengx 2020-09-10
颤抖吧腿子 2020-09-04
wwzaqw 2020-09-04
maple00 2020-09-02
青蓝 2020-08-26
罗忠浩 2020-08-16
liduote 2020-08-13
不知道该写啥QAQ 2020-08-02
pengruiyu 2020-08-01
wmd看海 2020-07-27
孝平 2020-07-18
Eduenth 2020-07-05
iftrueIloveit 2020-07-04