axios(网络请求模块)

axios:网络请求模块,是一个基于Promise 用于浏览器和 nodejs 的 HTTP 客户端。
功能特点:

  • 从浏览器中创建 XMLHttpRequests
  • 从 node.js 创建 http 请求
  • 支持 Promise API
  • 拦截请求和响应
  • 转换请求数据和响应数据
  • 取消请求
  • 自动转换 JSON 数据
  • 客户端支持防御 XSRF

基本使用

axios({
    
    
  url:'http://123.207.32.32:8000/home/multidata',
  //  传递参数
  params:{
    
    
  },
  method:'get'
}).then(res => {
    
    
  console.log(res)
})

多个并发请求

axios.all([
    axios({
    
    
      url:'http://123.207.32.32:8000/home/multidata'
    }),
  axios({
    
    
    url:'http://123.207.32.32:8000/home/multidata'
})]).then(results => {
    
    
  console.log(results)
})

在这里插入图片描述
数组展开式

axios.all([
    axios({
    
    
      url:'http://123.207.32.32:8000/home/multidata'
    }),
  axios({
    
    
    url:'http://123.207.32.32:8000/home/multidata'
})]).then(axios.spread((res1,res2) => {
  console.log(res1)
  console.log(res2)
}))

常见配置选项
在这里插入图片描述
创建axios实例

猜你喜欢

转载自blog.csdn.net/weixin_44495678/article/details/110846077
今日推荐