vue从入门到精通之进阶篇(三)axios

基本使用

Axios.method('url',[,..data],options)
.then(function(res){ })
.catch(function(err) { } )

合并请求

  • this.$axios.all([请求1,请求2])
    .then(  this.$axios.spread(function(res1,res2){  
            
            })
    )

拦截器

  • 单请求配置options: axios.post(url,data,options);

  • 全局配置defaults: this.$axios.defaults

  • config : 请求拦截器中的参数

  • response.config 响应拦截器中的参数

  • options

    • baseURL 基础URL路径

    • params 查询字符串(对象)

    • transformRequest 转换请求体数据

    • transformResponse 转换响应体数据

    • headers 头信息

    • data 请求体数据

    • timeout 请求超时,请求多久以后没有响应算是超时(毫秒)

你可能感兴趣的:(JavaScript,Vue,vue从入门到精通)