Question 24
Consider this Vue.js component code:
const TodoApp = { template: ` <div> <input v-model="newTodo" @keyup.enter="addTodo" /> <ul> <li v-for="todo in todos" :key="todo.id">{{ todo.text }}</li> </ul> </div> `, data() { return { newTodo: '', todos: [] } }, methods: { addTodo() { if (this.newTodo) { this.todos.push({ id: Date.now(), text: this.newTodo }); this.newTodo = ''; } } }}What happens when a user types "Learn Vue" into the input field and presses Enter?
Note: The @keyup.enter directive calls addTodo() when the Enter key is pressed.