Currently, I'm doing a website which repertories events organized my friend's music label. But I've encountered a problem while trying to make an "archiving automation". Using that code below is not working. My "articles" are still visibles on the blog page.
Here's what I've tried (it's working with a v-if on my nuxt-link, but not with a v-show). The reason why I don't use a v-if is that my links are still clickable, but not visible.
<div
class="article"
v-for="article in articles"
:key="article.slug"
v-show="dateNow < article.eventDate">
Here's my condition in my JS (not important but I prefer to show you guys)
data() {
return {
dateNow: new Date().toISOString()
};
},
I think the issue is in the formatting of the date.
new Date().toISOString()
this will format the date as a string. So the output value for ( >= ) operation will be incorrect. One solution is to turn the date into a timestamp by providing "+" before the date and then make the logical operation. ex:
+new Date()
or
new Date().getTime()
Or if you use a date library like "moment" you can use isSameOrAfter or isSameOrBefore APIs. https://momentjs.com/docs/#/query/is-same-or-after/