[Vuejs]-Format date within template interpolation – vue js

3👍

Can you define a method in your component and then use it like below?

<script>
import moment from 'moment';

export default {
    methods: {
        getFormattedDate(date) {
            return moment(date).format("YYYY-MM-DD")
        }
    }
}
</script>
<div v-for="(data, index) in variable" :key="index">
{{getFormattedDate(data.date)}}
</div>

Leave a comment