SoFunction
Updated on 2025-04-04

Based on Axios' commonly used request method alias (detailed explanation)

Axios

It is a promise-based HTTP library that can be used in browsers and .

Common request method alias are generally: Get/post/http protocol request

Perform a Get request

function get(){
 return ('/', {
    params:{
     id:1234
    }
    }).then(function (response) {
     (response);
    })
   .catch(function (error) {
    (error);
   });
 }

When using the get method to pass parameters, the params method is used.

Perform Post Request

function post(){
return ('/', {
  id:1234
    })
  .then(function (response) {
    (response);
  })
  .catch(function (error) {
    (error);
  });
 }

When using the post method to pass parameters, data is directly passed, which is also the difference between the two methods.

Execute http protocol request

function http(){
 return axios({
 method: 'post',
 url: '/',
 data: {
  id: 1111,
 },
params: {
 id:2222,
 }).then(res=>{
  =;
 });
}

Note the difference here. When using post request, the data method is used to pass data parameters, and when using get request, the params method is used.

Use interceptor:

Intercept requests or responses before they are processed by then or catch.

// Add a request interceptormounted:function(){
  (function (config) {
    // What to do before sending a request    return config;
   }, function (error) {
    // What to do about the request error    return (error);
   });
// Add a response interceptor  (function (response) {
    // Do something about the response data    return response;
   }, function (error) {
    // Do something to respond to errors    return (error);
   });
}

The above article is based on Axios' commonly used request method alias (detailed explanation) is all the content I share with you. I hope you can give you a reference and I hope you can support me more.