加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reflex中Action.do...();的事件执行顺序

发布时间:2020-12-15 03:30:19 所属栏目:百科 来源:网络整理
导读:场景 page文件里: mixins:[Reflux.connect(Store)],getInitialState: function () { Action.getInitData();}, store文件里: var Store = Reflux.createStore({ listenables: [Action],data: {},onGetInitData : function(){ var t = this; DB.Gate.getInit

场景

page文件里:

mixins:[Reflux.connect(Store)],getInitialState: function () {
    Action.getInitData();
},

store文件里:

var Store = Reflux.createStore({

    listenables: [Action],data: {},onGetInitData : function(){
        var t = this;
        DB.Gate.getInitData().then(function (data) {
            
            t.updateComponent();
        });
    },updateComponent: function () {
        this.trigger(this.data);
    },getInitialState: function() {
        var t = this;
        this.data = {
            
        };
        return this.data;
    }
});

module.exports = Store;

顺序

  1. 首先执行store里的getInitialState,

  2. 再执行react的componentDidMount,如果在componentDidMount里执行console.log(this.state),会输出空的state,render里console.log的话也是同样效果。

  3. 当DB.Gate.getInitData()执行完后,会更新state,但是componentDidMount不会执行第二遍,但是render里的console.log()会输出新的state。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读