Axe ios выставить запрос, отправка параметров и данных - PullRequest
2 голосов
/ 06 января 2020

У меня есть простое приложение todo, и я работаю над функцией редактирования задачи. Мой бэкэнд, кажется, работает правильно при тестировании. Я ищу req.body.description. Я редактирую задачу по id. Когда я сохраняю редактирование, внутри моей базы данных ничего не происходит. Моя функция заключается в следующем, почему это не работает?

function editTask(task) {
        const id = task.parent().parent().attr('id');
        const descript = task.parent().prev().text();
        axios.put('http://localhost:5000/api/tasks/:id', {
            params: {
                id: id
            },
            description: descript
        }).then(res => {
            console.log(res);
        }).catch(err => console.error(err));
    }

Ответы [ 2 ]

2 голосов
/ 06 января 2020

Я верю, что вы хотите:

axios.put(`http://localhost:5000/api/tasks/${id}`, {
            description: descript
        })
0 голосов
/ 06 января 2020
function editTask(task) {
   const id = task.parent().parent().attr('id');
   const descript = task.parent().prev().text();

   axios.put("http://localhost:5000/api/tasks/"+id, {
           description: descript
        }).then(res => {
            console.log(res);
        }).catch(err => console.error(err));
}
...