美文网首页AndroidStep
使用 umi-request 时的参数传递方式

使用 umi-request 时的参数传递方式

作者: sorry510 | 来源:发表于2021-10-16 11:44 被阅读0次

GET 使用 params,参数默认会被序列化到 url

request
  .get("/api/v1/xxx", {
    params: {
      id: 1
    }
  })
request
  .get("/api/v1/xxx?id=1")
image.png

POST,PUT,DELETE 使用 data

request
  .post("/api/v1/user", {
    data: {
      name: "Mike"
    }
  })
  .then(function(response) {
    console.log(response);
  })
  .catch(function(error) {
    console.log(error);
  });

如果 Content-Type 设置为 application/json,数据在 Request Payload

headers: { 'Content-Type': 'application/json' },
image.png

如果 Content-Type 设置为 multipart/form-data,数据在 Form Data

request
  .post("/api/v1/user", {
    headers: { 'Content-Type': 'multipart/form-data' },
    data: {
      name: "Mike"
    },
    requestType: 'form'  // 注意加个这个
  })
image.png

相关文章

网友评论

    本文标题:使用 umi-request 时的参数传递方式

    本文链接:https://www.haomeiwen.com/subject/yuqboltx.html