Reactjs AXIOS放置请求

时间:2018-12-19 21:27:25

标签: javascript axios

我有一个要从后端更改的前端用户。所以我做了一个AXIOS查询,但是没有用。

async updateUtilisateur(user) {
    const headers = {
        'authorization': localStorage.getItem(ACCESS_TOKEN)
    }

    const {id} = user.id;
    return await axios.put('/secure/utilisateur/${id}', 
        user,{headers}
    );
},

在我的后端日志中: o.s.s.w.u.matcher.AntPathRequestMatcher:检查请求的匹配情况:“ / secure / utilisateur / $ {id}”;反对“ / gestion-promotions / secure / **”

2018-12-19 22:21:19.018 WARN 1432 --- [io-8080-exec-14] .wsmsDefaultHandlerExceptionResolver:已解决[org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:无法转换以下项的值输入'java.lang.String'为必需的输入类型'java.lang.Integer';嵌套的异常是java.lang.NumberFormatException:对于输入字符串:“ $ {id}”]

id是我的请求中的PathVariable

1 个答案:

答案 0 :(得分:1)

您在此行上使用了错误的引号类型:

return await axios.put('/secure/utilisateur/${id}',

您使用的是“(单引号)而不是“(反引号) 这导致变量id未正确插入,然后将字符串${id}发送到后端。

要解决此问题,您可以使用反引号:

return await axios.put(`/secure/utilisateur/${id}`,

或:

return await axios.put('/secure/utilisateur/' + id,

有关JavaScript中反引号的更多信息:Template literals