Answer the question
In order to leave comments, you need to log in
I'm trying to display data from an axios request, why is data not updated?
export default {
name: "app",
components: {
Header,
Todos,
AddTodo
},
data() {
return {
todos: []
};
},
methods: {
deleteTodo(id) {
this.todos = this.todos.filter(todo => todo.id != id);
},
addTodo(newTodo) {
this.todos = [...this.todos, newTodo];
},
created() {
axios
.get("https://jsonplaceholder.typicode.com/todos")
.then(res => (this.todos = res.data))
.catch(error => error);
}
}
};
Answer the question
In order to leave comments, you need to log in
You have created in methods , so this is not a life cycle hook, but a method, it will not be called automatically.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question