nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.14k stars 628 forks source link

Search: Missing search data #2804

Closed EmileSpecs closed 1 month ago

EmileSpecs commented 1 month ago

Environment


Reproduction

https://github.com/EmileSpecs/nuxtcontentsearch

Describe the bug

Using the playground minimal example I added all the necessary setup steps to get search to work.

I however het the error: Missing search data

Can't find any information about anyone having this issue and I don't see anything that I've missed configuring search.

Can someone please assist?

Thanks!

Additional context

No response

Logs

No response

sooooooooooooooooootheby commented 1 month ago

This is because the await request will be executed once when the server renders, if you put it in the function will not happen Missing search data.

<script setup>
const search = ref("");
const results = ref([]);

const handleSearch = async () => {
    results.value = await searchContent(search);
}
</script>

<template>
    <main>
        <input v-model="search" />
        <button @click="handleSearch">search</button>

        <pre>{{ results }} </pre>
    </main>
</template>

However, he will have a strange warning that will ask you to replace 'searchContent' with '$fetch'

Image

EmileSpecs commented 1 month ago

@sooooooooooooooooootheby thanks, that solved it.