正如标题所说,在异步/等待函数中时,我需要使用.then。两者之间的有效方式是什么
setPersonList = async ()=> { const personList = []; await this.firestoreCollection .get() .then(result => { personList = { ...result.data }; }); return personList ; };
或
setPersonList = async () => {
const personList = [];
const snapshot = await this.firestoreCollection
.get()
snapshot.docs.forEach((doc) => {
personList .push(doc.data());
});
return personList ;
};
正如标题所说,在异步/等待函数中时,我需要使用.then。这两个setPersonList = async()=> {const personList = [];之间的有效方式是什么?等待这个...。
通常,将async / await与then / catch链结合在同一诺言上不是一个好主意。 async / await的全部目的是允许使用更可读的代码,而不涉及使用then / catch嵌套回调。