AndroidStep

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

2021-10-16  本文已影响0人  sorry510

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
上一篇 下一篇

猜你喜欢

热点阅读