The Blog of Rizal Renaldi

Rizal Renaldi

← Back

Nuxt Content by Category

12 May 2021

code

What to achieve:
Displaying posts on specific category in Nuxt Content using AsyncData

async asyncData({ $content, params }) {
    const tipsPosts = await $content('articles')
                        .where({ categories: { $contains: 'tips' }})
                        .sortBy('id', 'desc')
                        .fetch()
    return {
        tipsPosts
    }
},

The filtering occur in line 3 using .where and $contains with the category name as parameter.

The Blog of Rizal Renaldi

2024 © rizalrenaldi.com — Made with 🖖