NuxtN
Nuxt2y ago
Insight

Filter await useFetch

Hi I am new to Nuxt and all the javascript frameworks out there. I am trying to pull data and then filter it on the page. However when I try to run .filter on questions it comes back stating that questions doesn't have a method named .filter() I see that it returns a Ref<SerializedObject> but how would I get this to work as expected?
<script setup lang="ts">
const { data: questions } = await useFetch('/api/faq')
const searchText = ref("")
const filteredQuestions = computed(() => {
    if (searchText.value == "") {
        return questions;
    }

    const t = searchText.value.toLowerCase();
    return questions.filter(item => {
        return item.question.toLowerCase().includes(t) || item.answer.toLowerCase().includes(t);
    });
})
</script>
Was this page helpful?