2

I'm building a small app with nuxt3 and the Directus module. In my Directus project I have a collection called "Prestations" with a field called "active".

In my app, I want to query all the items from this collection where active === true.

I use this that works well, but it fetches ALL items:

const { getItems } = useDirectusItems();

getItems({ collection: "Prestations"})
.then(res => {
        console.log(res)
})
.catch(err => {
    console.log(err.message)
})

I tried a bunch of variations of things like this:

getItems({ collection: "Prestations",
           filter: {
               "active": {
                 "_eq": true
               }
           }
})
.then(res => {
        console.log(res)
})
.catch(err => {
    console.log(err.message)
})

I don't really understand how to use the global query parameters. I looked in the documentation, but I couldn't find a full example. Only bits and bobs that I try to fit together with no results.

What is the proper way to filter the results of a query?

Posoroko
  • 189
  • 1
  • 2
  • 11

1 Answers1

1

Warp your query parameters in params:

For example:

getItems({
    collection: 'articles',
    params: {
      limit: 10,
      fields: ['id', 'title', ...],
      sort: '-date_created'
    }
  })
YiX H.
  • 11
  • 1