最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nuxt3.js - How to handle markdown content in Nuxt3 using nuxtcontent - Stack Overflow

programmeradmin1浏览0评论

I'm trying to display some images and title from my markdown content in my nuxt3 project.

 ---
title: A selection of our customers

images:
  - /images/brands/brand-1.png
  - /images/brands/brand-2.png
  - /images/brands/brand-3.png
  - /images/brands/brand-4.png
---

It's my content/home/brands.md file.

This is my index.vue

<template>
  <HeroSection />
  <BrandSection :brands="brands" />
</template>

<script setup>
// Fetch brands data from content directory
const { data: brands } = await useAsyncData('brands', () => queryContent('/home/brands').findOne())
console.log(brands.value)
</script>
<style scoped>
</style>

And this is brandSection.vue

<template>
    <div class="bg-white-secondary">
        <div class="max-w-[1440px] mx-auto px-[100px] py-[80px]">
            <h2 class="text-2xl font-medium mb-8">{{ brands?.title }}</h2>
            <div class="flex gap-[100px] items-center justify-center">
                <NuxtImg 
                    v-for="(image, index) in brands?.images" 
                    :key="index"
                    :src="image" 
                    :alt="'Brand logo'"
                    class="h-[50px] object-contain" 
                />
            </div>
        </div>
    </div>
</template>
<script setup>
const {brands} = defineProps(['brands'])
</script>
<style scoped></style>

But it isn't displayed.

Please help me to fix this issue and render correctly.

I'm trying to display some images and title from my markdown content in my nuxt3 project.

 ---
title: A selection of our customers

images:
  - /images/brands/brand-1.png
  - /images/brands/brand-2.png
  - /images/brands/brand-3.png
  - /images/brands/brand-4.png
---

It's my content/home/brands.md file.

This is my index.vue

<template>
  <HeroSection />
  <BrandSection :brands="brands" />
</template>

<script setup>
// Fetch brands data from content directory
const { data: brands } = await useAsyncData('brands', () => queryContent('/home/brands').findOne())
console.log(brands.value)
</script>
<style scoped>
</style>

And this is brandSection.vue

<template>
    <div class="bg-white-secondary">
        <div class="max-w-[1440px] mx-auto px-[100px] py-[80px]">
            <h2 class="text-2xl font-medium mb-8">{{ brands?.title }}</h2>
            <div class="flex gap-[100px] items-center justify-center">
                <NuxtImg 
                    v-for="(image, index) in brands?.images" 
                    :key="index"
                    :src="image" 
                    :alt="'Brand logo'"
                    class="h-[50px] object-contain" 
                />
            </div>
        </div>
    </div>
</template>
<script setup>
const {brands} = defineProps(['brands'])
</script>
<style scoped></style>

But it isn't displayed.

Please help me to fix this issue and render correctly.

Share Improve this question asked Feb 3 at 7:58 Pegasus ProngsPegasus Prongs 231 silver badge6 bronze badges 4
  • Any errors in the console? What do you see in the devtools? – kissu Commented Feb 3 at 12:07
  • No errors. console.log(brands.value) //NULL – Pegasus Prongs Commented Feb 3 at 12:32
  • Can use MDC: docs4.dev/posts/… – Chris Wong Commented Feb 5 at 12:05
  • I just solved problem. Nuxt content v3.1.0 use queryCollection instead of queryContent. Thanks for your comments. – Pegasus Prongs Commented Feb 10 at 19:29
Add a comment  | 

1 Answer 1

Reset to default 0

I just solved problem. In nuxt content v3, queryContent() API is replaced with new queryCollection() https://content.nuxt/docs/getting-started/migration

发布评论

评论列表(0)

  1. 暂无评论