为什么resolve()必须在提交之前发生?

时间:2018-10-02 01:43:16

标签: javascript vue.js promise axios vuex

我正在与Vue&Vuex合作,在Promise中对服务器进行相当简单的axios DELETE调用。

我注意到DELETE调用正常运行,Vuex提交也正常运行,但是我的决心没有实现。

我通过在我的commit()之前放置resolve()来使一切正常,但是我不明白为什么需要这种方式。

希望有人能回答我,以便我学习。请参见下面的代码,并预先感谢您。

export const remove = ({ state, commit }, uid) => {
  return new Promise((resolve, reject) => {
    t.$axios.delete(t.$consts.DELETE_URL + '/' + uid).then((response) => {
        if (response.status === 200) {
            resolve()
            commit('remove', uid)
        }
    }).catch((error) => {
        reject(error.response)
    })
  })
}

0 个答案:

没有答案
相关问题