[Vuejs]-Making a custom function for a mapped array in VueJS for a table

2👍

The value item.LastUpdatePostDate is a string… it has no newFunction method. The newFunction method is available via this.newFunction, and you should pass the date string as argument:

LastUpdatePostDate: this.newFunction(item.LastUpdatePostDate),

newFunction itself could look like this:

newFunction: function (dateString) {
    let [monthName, day, year] = dateString.match(/\w+/g);
    let month = "JanFebMarAprMayJunJulAugSepOctNovDec".indexOf(monthName.slice(0, 3)) / 3 + 1;
    return `${day}/${month}/${year}`.replace(/\b\d\b/g, "0$&");
}

But maybe give it a more telling name 😉

1👍

You cannot call a vue method on a value.

Call the method with the value as argument:

...
    LastUpdatePostDate: this.newFunction(item.LastUpdatePostDate),
...
newFunction(date) {
    // do stuff with date
    return newvalue
}
....
👤tauzN

Leave a comment