arrays - 由于 vueJS,精神崩溃了一半
问题描述
嘿,我正在尝试从我的 Firestore 数据库中获取数据。问题是 vue 不想在逻辑上计算我的数组,而且我认为我从 vue 得到的响应没有任何意义。
编码
const uid = store.state.user.uid;
var qry = maintainCollection.where('users', 'array-contains', uid)
const test = [];
qry.get().then(snapshot => {
snapshot.docs.forEach(doc => {
test.push(doc.data())
})
});
var sorted = test.sort(function (a, b) {
if (a.deadline < b.deadline) {
return -1
} else {
return 1
}
});
console.log(sorted[0])
所以现在当我使用索引 0 进行排序时,我得到了未定义的结果。
而且,当我尝试对数组进行排序时,它根本不起作用。
解决方案
推荐阅读
- javascript - Next.js - 动态图像
- x86 - 为什么 adox 和 adcx 在 Ryzen 上不能很好地配合使用?
- python - 如何在文件夹中使用文件夹中的齿轮
- ruby-on-rails - 如何将 stylesheet_link_tag 与 sprockets 4 一起使用?
- sql - 选择中的默认值 - SQL
- javascript - 在 axios post 方法中设置状态
- swift - 为什么即使在 Swift 中删除 FireStore 对象,我仍然能够获取数据?
- python-3.x - 如何使用字典计算 Python 中单词中“边”的数量?
- javascript - 无法使用 https 可调用从云函数返回数据
- javascript - 我可以只使用一个来打印 fetch API 数据吗?