content
content copied to clipboard
useContent() available in normal mode
Hi! I'm new to Github so I hope this is the right place for that
Is your feature request related to a problem? Please describe
I would like to access the content object containing the title, content, etc from my /content/blog.
I have a [...slug].vue
file in my /pages/blog folder, where I'd like to access the article info. I saw we could use useContent()
to access it but for that I need to enable "document driven mode". It would be nice to be able to access it directly.
Describe the solution you'd like
Instead of having to enable documentDriven mode in the config, have useContent accessible by default.
Describe alternatives you've considered
It kinda works with queryContent() but isn't it overkill? Like, isn't it going to re-fetch the article after it was sent to the template? Could be nice to have access to all document data directly
const route = useRoute()
const slug = '/blog/' + route.params.slug.join('/')
const { data } = await useAsyncData('home', () => queryContent(slug).findOne())
const { body, categories, date, description, title, _path, _slug } = data.value
console.log(description, title)
Additional context
My page:
<template>
<main>
<ContentDoc>
<template #not-found>
<h1>Oops... 😬</h1>
<p>It looks like this page doesn't exist.</p>
</template>
<template v-slot="{ doc }">
<p class="article-date">{{ doc.date }}</p>
<h1 class="article-title">{{ doc.title }}</h1>
<NuxtImg class="article-img" :src="`/images/blog/${doc.coverImage}`" :alt="doc.title" width="500px" />
<ContentRenderer :value="doc" class="page-formating" />
</template>
</ContentDoc>
</main>
</template>