给出以下名为init
且可正常运行的vuex动作,该动作可获取settings
和accounts
集合:
actions: {
init: firestoreaction(({ bindFirestoreRef,commit },payload) => {
bindFirestoreRef(
'settings',fb.settings.doc(payload),)
.then(() => commit('SETTINGS_READY',true))
.catch((err) => {
commit('snACKBAR_TEXT',err.message);
Sentry.captureException(err);
});
bindFirestoreRef(
'accounts',fb.accounts.where('program','==',payload),)
.then(() => commit('accOUNTS_READY',err.message);
Sentry.captureException(err);
});
}),},
我有两个问题:
- 代码似乎是同步运行的,但是我希望异步获取两个集合以最大化性能。如何实现?
- 是否可以重构此代码以使其更简洁,同时提供示例中提供的独立(和同步)
then/catch
功能?