vuex 异步操作未异步加载。仅在页面重新加载后加载

时间:2021-01-21 23:05:26

标签: google-cloud-firestore vuex

我需要一个异步操作。当前内容仅在页面重新加载后加载。需要帮助找出最适合我的情况的方法。

async getConversation ({ commit }, routeParamsId) {
    commit(RESET_CONVERSATION)

    const conversation = await db.collection('conversations').doc(routeParamsId).get()

      if (conversation.exists) {

        commit('SET_CONVERSATION', {
          id: conversation.id,
          ...conversation.data()
        })

      }

      if(conversation.data().conversations) {

        commit(RESET_CHAT)

        conversation.data().conversations.forEach(function(item){ 
          db.collection('dialogue').doc(item).get().then(snapshot => {
            commit('modules/dialogue/PUSH_CHAT', {
              id: snapshot.id,
              ...snapshot.data()
            }, {root: true})
          })
        })

      }

  }

}

我正在设置对话,然后“对话”集合有一个代表对话集合的 id (conversation.data().conversations) 数组。这些 id 用于在视图中加载我的对话集合。正确执行此操作的最佳方法是什么?谢谢!

0 个答案:

没有答案