Why is nuxt content not getting my stuffImageconst { data: prizes } = await useAsyncData('prizes',

4 Replies
Hi @Uchuu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
const { data: prizes } = await useAsyncData('prizes', () => {
return queryCollection('prizes').first()
})
But prizes is empty
import { defineContentConfig, defineCollection, z } from '@nuxt/content'
export default defineContentConfig({
collections: {
prizes: defineCollection({
type: 'data',
schema: z.object({
items: z.array(z.object({
title: z.string(),
slug: z.string(),
description: z.string(),
date: z.string(),
prize: z.string(),
speciality: z.string(),
org: z.object({
name: z.string(),
slug: z.string()
})
----------------------
I'm sorry, but the knowledge sources do not provide enough information to determine why your Nuxt Content query (
const { data: prizes } = await useAsyncData('prizes', ...)
) is not retrieving your "stuffImage" or expected data.
However, here are some relevant points from the documentation that might help you troubleshoot:
1. Collection Definition: When using Nuxt Content with JSON files, you must define your collection and schema in content.config.ts
. Each file in a data
collection should contain only one object (no top-level arrays). Make sure your JSON files and schema are set up correctly, and that the field you expect (like stuffImage
) is included in the schema and present in your JSON files Nuxt Content JSON Files.
2. Querying Data: To query a collection, you typically use queryCollection('collectionName')
within your async function. For example:
Ensure that your query matches the structure and naming of your collection and files Nuxt Content JSON Files.
3. Key Uniqueness: When using useAsyncData
, the key ('prizes' in your example) should uniquely identify the data being fetched, especially if you are using features like shared prerender data Nuxt Data Fetching.
If you are still not seeing your expected data, please check:
- That your JSON files are in the correct directory (content/prizes/
if your collection is named "prizes").
- That the schema in content.config.ts
includes all the fields you want to access.
- That your query is correct and matches the collection and file structure.
If you can provide more details or error messages, I may be able to help further.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1035470271441805353> Kapa.ai is still learning and improving, please let me know how I did by reacting below.