1. 创建一个request.js文件
import axios from 'axios' import { MessageBox, Message } from 'element-ui' /** * @template axios请求封装 拦截 * @author daidai */ const service = axios.create({ withCredentials: false, // 跨域请求时是否需要使用凭证 baseURL: '/api', timeout: 5000 // request timeout }) /** * @template axios请求拦截器 * @author daidai 作者 * @param config 请求头信息 */ service.interceptors.request.use( config => { // 可以设置请求头和token信息 // const TOKEN = localStorage.getItem('Token') // // const TOKEN = 'sadwsasdasd' // if(TOKEN){ // config.headers['Content-Type'] = 'application/json'; // config.headers['Authorization'] = TOKEN; // } return config }, error => { // do something with request error console.log(error) // for debug return Promise.reject(error) } ) /** * @template 响应拦截器 * @author daidai 作者 * @par