Skip to content

Instantly share code, notes, and snippets.

@spyl94
Created November 8, 2018 10:53
Show Gist options
  • Save spyl94/7ca721033e1cd4c235a4d0cd5700034d to your computer and use it in GitHub Desktop.
Save spyl94/7ca721033e1cd4c235a4d0cd5700034d to your computer and use it in GitHub Desktop.
<template>
<div id="app" class="App">
<p class="my-component">
Je suis mon premier composant
</p>
<ul>
<li v-for="todo in todos" :key="todo.id">
{{ todo.name }} - {{ todo.dueDate.toLocaleString() }}
</li>
</ul>
<input type="text" v-model="newTodo" @keyup.enter="addTodo" placeholder="Entrez votre todo...">
</div>
</template>
<script>
export default {
name: "app",
methods: {
addTodo() {
if (this.newTodo === "") return;
const id = this.todos[this.todos.length - 1].id + 1;
const todo = {
id,
name: this.newTodo,
dueDate: new Date()
};
this.todos.push(todo);
this.newTodo = "";
}
},
data() {
return {
newTodo: "",
todos: [
{
id: 1,
name: "Todo 1",
dueDate: new Date()
},
{
id: 2,
name: "Todo 2",
dueDate: new Date()
},
{
id: 3,
name: "Todo 3",
dueDate: new Date()
},
{
id: 4,
name: "Todo 4",
dueDate: new Date()
}
]
};
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment