vue项目中,用axios获取当前页面header信息


组件中,引入axios,get请求当前页面,在拦截器中获取config

import axios from ‘axios’

created(){
  // 添加请求拦截器
  axios.interceptors.request.use(function (config) {
    // 这里打印的config就可以获取到header信息
    console.log(config)
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });
  axios({
    url: 'http://localhost:8081/user', //当前页面地址
    method: 'get',
  })

}

  

posted @ 2022-05-14 10:50  zwbsoft  阅读(4020)  评论(0编辑  收藏  举报