-
problemI have some md-based posts, each with different time format. For instance:
I'd like to sort the posts based on the time, so I need to do something like: posts.sort((a, b) => +new Date(b.date) - +new Date(a.date) But the alternatives triedI can think of another approach of doing this, buy just collecting the post info in a **Question: ** What should I do now...? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think this doesn't work with functions because they currently can't be stringified. 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> |
Beta Was this translation helpful? Give feedback.
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: