axios understanding

1. Axios understanding:
axios is a encapsulated ajax, a network request library, in the learning process you must learn to send requests and get the content of the response; it is the key to the front-end separation technology
2. The following is the grammatical format of get and post:
( Please understand get and post
https://www.cnblogs.com/weituanbing/archive/2019/05/30/10950765.html
This article is relatively popular, and it will not be the same as other articles after reading it.)



//get语法格式:
axios.get(地址?查询字符串).then(function (response){},function (err) {})
       //如果要传递参数,就   ?查询字符串;
       //查询字符串格式:key=value&key2=value2  ,key是文档提供的,value是具体要传输的数据
       //function (response)会在请求完成响应的时候触发,response这个     参数是获取服务器响应的内容
       //function (err)会在请求失败的时候触发,err这个参数是错误的信息
axios.post(地址,参数对象).then(function (response){},function (err) {})
      //参数对象格式:{key:value,key2:values}

Please pay attention to compare and remember the difference between get and post syntax.
After understanding the syntax of get and post, you can look at the following example:

//举例

// 直接在 URL 上添加参数 ID=12345
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

In addition to get and post functions, axios has other functions, please refer to:
https://github.com/axios/axios

For ease of use, the official provides aliases for all supported request methods, and you can directly use the alias to initiate a request:
axios.request(config)
axios.get(url[, config])
axios.delete(url[, config])
axios .head(url[, config])
axios.post(url[, data[, config]])
axios.put(url[, data[, config]])
axios.patch(url[, data[, config]] )

Guess you like

Origin blog.csdn.net/qq_42850073/article/details/114026476