如何在axios PUT请求中传递参数?

问题描述 投票:0回答:2
axios.put('http://localhost:3000/api/userDatas/findUserAddProp',{
    params: {
        userId: "5bb8c3bd16bf1f515ce5b42f",
        prop: "questions",
        questionId: "5bb8c466cb49d8421c05eeda"
    }
});

服务器

Userdatas.findUserAddProp = function(req, res, cb) {
    const queryId = req.query.userId;
    const propToUpdate = req.query.prop;
    const questionId = req.query.questionId;

    console.log("queryId: ", queryId);
    console.log("propToUpdate: ", propToUpdate);
    console.log("questionId: ", questionId);
    ...
}

这是控制台上的服务器输出。

queryId:  undefined
propToUpdate:  undefined
questionId:  undefined

为什么会发生这种情况我只是将所有参数传递给服务器?

axios loopbackjs put
2个回答
0
投票

你试过了吗

req.params.userId

req.param用于读取像/user/:id这样的Url Params,而req.query用于读取http:localhost:8080/api/users?id=123等查询参数


0
投票

put方法需要一个额外的参数“data”(在请求体中发送):

axios.put(url[, data[, config]])

将它传递为null,你就完成了:

axios.put('http://localhost:3000/api/userDatas/findUserAddProp', **null,** {
...
© www.soinside.com 2019 - 2024. All rights reserved.