Reputation: 15
I'm displaying the list of holidays where in the array the specific day (e.g 'MMMM-01-YYYY' in my array it's written like this dateHoliday: "01") I want to catch the day included in my array and display it (e.g "Mon" like this.)
I tried using moment and what I achieved is to display the current day(today). I can't get the array the I want.
<template>
<h2>{{ Holiday.dateHoliday }}</h2>
</template>
import moment from "moment";
export default {
data() {
return {
Holidays: [
{
id: 1,
Month: "January",
day: "Tue",
dateHoliday: "01",
Title: "new year's day",
Description: "Description: Regular holiday."
}
methods: {
displayDay(){
let dH = moment().format("ddd");
this.dateHoliday = dH;
console.log(this.dateholiday);
}
edit
I tried Capt. Teemo's answer. I changed one of my string in the array.
day: "Tue",
dateHoliday: "01",
to
day: "01-01-2019",
dateHoliday: "01",
then in my template:
<h2>{{ Holiday.dateHoliday }}</h2>
<h2>{{ Holiday.day | convertDay }}</h2>
But in the property(day) i don't want it to be specific (e.g 01-01-2019. I want it like 01-01-xxxx where its filtered? to the year i want).
Upvotes: 1
Views: 43
Reputation: 2164
try this method in using moment
:
I used vue filters
. Add these lines after your method
methods: {
},
filters: {
convertDay: function (value) {
return moment(new Date(value)).format('ddd')
},
}
then use the filter that you created:
<template>
<h2>{{ Holiday.dateHoliday | convertDay }}</h2>
</template>
Upvotes: 1