vue中获取接口的方法

214 阅读1分钟

post简写

axios
  .post("", {
    username: "admin",
    password: '123456',
  })
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log(err);
  });
  
  

** // post全面写** axios ({

  url: "",
  method: "POST",
  data: {
    username: "admin",
    password: "123456",
  },
})
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log(err);
  })
  
  

** get简写**

axios
  .get("")
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log(err);
  }); 
  
  

get不简写 axios({

  url: "",
  method: "get",
  params: {
    pagenum: 1,
    pagesize: 10,
  },
  headers: {
    Authorization:
      "",
  },
})
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log(err);
  });