zoukankan      html  css  js  c++  java
  • 设置拦截器,过滤响应数据

    // 创建axios实例
    const service= axios.create({
    
      baseURL:'/api',//配置基础路径
      timeout:3000
    })
    
    //请求拦截器
    service.interceptors.request.use(config=>{
      //发送请求,开始进度条
      Nprogress.start()
      return config
    })
    
    // 响应拦截器
    service.interceptors.response.use(
      response=>{
        Nprogress.done()
        return response.data
        // return response
       
      },
    
      error=>{
        Nprogress.done()
        alert('请求出错le'+error.message || '未知错误')
        return new Promise(()=>{})
      }
    )

    发送ajax获取的数据

     注;原始的response有很多数据,我们需要过滤数据,则response.data

  • 相关阅读:
    7、猜年龄
    6、continue语句
    5、break语句
    4、while循环练习
    poj 2378
    poj 2342
    poj 2287
    poj 2228
    poj 1191
    srm 578 dv2 1000pt
  • 原文地址:https://www.cnblogs.com/fsg6/p/13321937.html
Copyright © 2011-2022 走看看