[Vuejs]-How to add a new Task into the parent component array?

0👍

I checked your project and I found the error.

async addTask(context, data) {
    const res = await fetch('https://jsonplaceholder.typicode.com/todos', {
      method: 'POST',
      headers: {
        'Content-Type': 'appication/json;charset=utf-8',
      },
      body: JSON.stringify(data),
    });
    if (res.ok) {
      let result = await res.json();
      context.dispatch('getTasks');
    }
    return res.ok;
},

When you call API, Backend doesn’t add newTask, This is error.
So when you get response, there isn’t newTask data that you added.

Leave a comment