vue的axios请求

82 阅读1分钟

GET 请求 // 直接在 URL 上添加参数 ID=12345

axios.get('/user?ID=12345')
  .then(function (response) {
  })
  .catch(function (error) {
    console.log(error);
  });

// 也可以通过 params 设置参数:

axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
  

POST 请求

axios.post('/user', {
    firstName: 'Fred',        // 参数 firstName
    lastName: 'Flintstone'    // 参数 lastName
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });