M
M
Martian_o2019-05-05 14:06:51
Vue.js
Martian_o, 2019-05-05 14:06:51

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

2 answer(s)
0
0xD34F, 2019-05-05
@Martian_o

You have created in methods , so this is not a life cycle hook, but a method, it will not be called automatically.

A
Alexey Shashenkov, 2019-05-05
@teknik2008

everything is written here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question