javascript - vuex asynchronous update problem
迷茫
迷茫 2017-05-18 10:57:51
0
2
454
 this.$store.dispatch('analyzesDetail', id).then(() => {
                        this.temp = this.$store.state.nlp.analyzesDetail.content;
                        //...
                    });

After the analyzeDetail action is completed, I obtain the analyzeDetail in the state. Why is it still the previous data?

action

analyzesDetail({commit}, id){
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            request(
                {
                    method: 'get',
                    url: `/agent/nlp/analyze/${id}`,
                },
                {type: nlpTYPE.ANALYZES_DETAIL},
                {type: nlpTYPE.ANALYZES_DETAIL_ERROR, message: '获取分析详细失败'},
                commit);
            resolve()
        }, 100)
    })
},

const mutations = {
[nlpTYPE.SEGMENT] (state, payload) {
    state.segment = payload;
},
[nlpTYPE.ANALYZE] (state, payload) {
    state.analyze = payload;
},
[nlpTYPE.CURRENT_ANALYZE] (state, payload) {
    state.currentAnalyze = payload;
},
[nlpTYPE.ANALYZES] (state, payload) {
    state.analyzes = payload;
},
[nlpTYPE.ANALYZES_ID] (state, payload) {
    state.analyzesId = payload;
},
[nlpTYPE.ANALYZES_DETAIL] (state, payload) {
    state.analyzesDetail = payload;
},

};

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
为情所困

Using watch to solve this problem, use watch to monitor analyzeDetail, and then calculate the data I want after the change; but I feel that this is only a temporary solution, I can still figure out why promise does not work

洪涛

This in the arrow function is not a vue instance, so it will not be updated.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template