Skip to content

Customized sorting function for queryContent #2263

Answered by nobkd
xarthurx asked this question in Q&A
Discussion options

You must be logged in to vote

I think this doesn't work with functions because they currently can't be stringified.
This is needed because the whole query is included in a request to an internal Nuxt API endpoint.
I can't find the corresponding issues/discussions... So I might be wrong...


Something like the following should work:

<script setup>
let { data: posts } = await useAsyncData('xblog', () => queryContent('/blog').only(['title', '_path', 'date']).find())
// do something with `posts`' ref
// e.g.
posts.value.sort((a, b) => new Date(b.date) - new Date(a.date))
// don't take my word here, I'm not sure when it comes to refs
</script>
<template>
  <pre>
  {{ posts }}
  </pre>
</template>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@xarthurx
Comment options

Answer selected by xarthurx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants