首页 > 移动平台 > 详细

axios拦截器

时间:2020-04-10 16:39:24      阅读:70      评论:0      收藏:0      [点我收藏+]

1、请求拦截器  在请求发出之前设置一些信息

    axios.interceptors.request.use(function(config) {
            console.log(config.url);
            config.headers.mytoken = ‘nihao‘; // 设置请求头
            return config;
        }, function(error) {
            console.log(error);
        });
        axios.get(‘http://localhost:3000/adata‘).then(function(res) {
            console.log(res.data);
        })

2、响应拦截器  再获取数据之前对数据进行一些加工处理

    axios.interceptors.response.use(function(res) {
            var data = res.data
            return data;
        }, function(error) {
            console.log(error);
        });
        axios.get(‘http://localhost:3000/adata‘).then(function(res) {
            console.log(res);
        })

  

axios拦截器

原文:https://www.cnblogs.com/Alisa-k/p/12674363.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!