I would like to transform a date with the .toLocaleDateString() but I can't figure out what is wrong with the code below. I have tried to pass todo.dueAt to a method defined under the <script> tag which would return with the transformed date, but I got the same TypeError: todo.dueAt.toLocaleDateString is not a function"issue.
Why it should be a function at all and why is it work only with the todo.dueAt?
<template>
<div class="todo-table">
<table>
<thead>
<tr>
<th>Done</th>
<th>Title</th>
<th>Created</th>
<th>Due Date</th>
</tr>
</thead>
<tbody>
<tr v-for="todo in todos" :key="todo.id">
<td> {{ todo.isCompleted}}</td>
<td> {{ todo.title }}</td>
<td> {{ todo.dueAt.toLocaleDateString("hu-HU") }}</td>
<td> {{ todo.dueAt.toLocaleDateString("hu-HU") }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
name: "TodoList",
props: {
todos: Array
},
method: {
formatDate: (date) => {
return date.getFullYear() + "." + (date.getMonth() + 1) + "." + date.getDate();
}
}
}
</script>
todo.dueAtis not aDatetodo.dueAtis really of typeDate? It could be of typestring, and that's a reason for this errortodosarray. Are you sure thattodo.dueAtexists and is a JavascriptDateobject? Does your browser supporttoLocaleDateStringyet? You can check that by executingconsole.log((new Date()).toLocaleDateString)in your dev console and making sure that it returns a function and notundefined.