首页 > 解决方案 > 由于 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 进行排序时,我得到了未定义的结果。
而且,当我尝试对数组进行排序时,它根本不起作用。

标签: arraysvue.jssortinggoogle-cloud-firestorevuejs2

解决方案


推荐阅读