FoxCode
Nuxt Content v3 layouts
I'm migrating my project from Nuxt Content v2 to v3, and almost every page in my project uses a layout. Unfortunately, there's an issue with this: when navigating to another subpage (without a hard reload), the layout glitches, sometimes duplicates, and so on.
To check the layout on each page, I'm forced to create a collection that includes all possible .md files:
content: defineCollection({
type: 'page',
source: '*/**.md'
}),
so that I can use:
const route = useRoute()
const { data: page } = await useAsyncData(route.path, async () => {
return queryCollection('content').path(route.path).first()
})
so that I can later use:
<NuxtLayout :name="page?.meta?.layout || 'default'">
<NuxtPage />
</NuxtLayout>
After navigating to /getting-started/usage and then clicking a button that redirects to /getting-started/test, the layout does not update. However, if I do a hard refresh, it loads correctly.
How should I properly handle layouts in this case?
And - is there an alternative approach to the Document-Driven mode that doesn’t require creating a collection of ALL md files?
Wouldn't this duplicate content in the database? I’m using this collection only for [..slug].vue to display the correct page based on the URL.
What can be done about this? Maybe I’m using the new features incorrectly, or is this a bug?
PS. how can I prevent these types of issues in the future, where a hard refresh behaves completely differently from a regular navigation—especially during development?
github issue: https://github.com/nuxt/content/issues/3107
10 replies
[Content 3] Multiple sources
According to https://content.nuxt.com/docs/collections/sources
Can I create collection with multiple sources? For example:
4 replies
NuxtContent 3, how to change data inside script setup
My code:
I would like to take the
tabs
, use .filter
and so on, and then display the processed data on the page. Unfortunately, useAsyncData seems to execute too late. How can this be fixed?11 replies
NuxtScripts usage
Is it possible using NuxtScripts to run a script with a component and imports? eg. https://cdn.jsdelivr.net/npm/@img-comparison-slider/[email protected]/dist/index.esm.js
1 replies
Error but no fail (failOnError: true)
failOnError
is set to true, and it always worked fine, but today when generating the page something went wrong, an error appeared and at the same time it did not throw an error but it is visible in the logs, why? The error was an incorrect syntax in the .md file parsed by nuxt-content.
Logs:
1 replies
How to make only one request when website build
I created plugin like this: https://github.com/nuxt/nuxt.com/blob/main/plugins/stats.ts
but i get
[error] [nitro] [unhandledRejection] [GET] "https://api.github.com/repos/xyz": 429 too many requests
xtimes on yarn generate
.
I changed $fetch('https://api.nuxt.com/stats')
to
3 replies
Accordion in nuxt-content
I want to create accordion component for nuxt-content markdown. I thought it would use NuxtUI Accordion (https://ui.nuxt.com/components/accordion) I would like every H2 to be turned into a title in accordion and the rest of the content to be hidden to make markdown look normal, like here:
Or if it is possible to create multiple slots simultaneously:
But I don't know how to get to the slots in the normal way, I tried:
but
MDCSlot
runs the entire $slots.default, and using the same slot name makes it rendered one at a time
Or if its not worth doing - can I use slots like this?
Accordion.vue: <UAccordion :items="items" />
2 replies
useRoute not working with static website?
Hi, why class "active" is not working with prerender static website? My reproduction code: https://stackblitz.com/edit/github-xwmppm?file=pages%2Findex.vue
Code is like this:
and localhost:3000?active=0 NOT WORKING
and localhost:3000?active=0 WORKING
Why and how to fix that?
1 replies
JavaScript heap out of memory with v3.6.2
I have quite a few .md files using nuxt-content,
yarn generate
usually took a few minutes, but after upgrading to the latest version of nuxt after a while it throws a JavaScript heap out of memory error. Why is nuxt now consuming so much memory, how to check the memory consumption and can it be optimized somehow
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1 replies