javascript Vue3预期在控制台中显示数据,但未显示任何内容

gkl3eglg  于 2023-02-02  发布在  Java
关注(0)|答案(1)|浏览(193)

我尝试在控制台上打印MongoDB集合(collection 1Data)中的所有文档,但没有任何内容出现。我不确定问题是什么,我认为console.log语句的位置可能不正确。控制台未显示错误console.log(collection1Data.value.filter(data =〉isRecentlyUpdated(data.updatedAt));

<script setup>
import { ref, onMounted } from 'vue';
import axios from 'axios';
  
    const collection1Data = ref([]);
    const collection2Data = ref([]);

    const fetchData = async () => {
      const [collection1Response, collection2Response] = await Promise.all([
        axios.get('https://koh-ontvsound:53500/onboardshows'),
        axios.get('https://koh-ontvsound:53500/onboardlands'),
      ]);
      collection1Data.value = collection1Response.data;
      collection2Data.value = collection2Response.data;
      
      console.log(collection1Data.value.filter(data => isRecentlyUpdated(data.updatedAt)));

    };

    onMounted(() => {
      fetchData();
      setInterval(fetchData, 1000);
    });

    const isRecentlyUpdated = (updatedAt) => {
      const updatedTime = new Date(updatedAt);
      return (Date.now() - updatedTime.getTime()) < 15000;
    };

</script>
e0bqpujr

e0bqpujr1#

你没有解析传入的响应数据

collection1Data.value = (await collection1Response.json()).data;
collection2Data.value = (await collection2Response.json()).data;

相关问题