首先描述下问题:需求是在请求头中加入token,我在ajax请求数据时添加了请求头‘Authorization’字段,并添加了响应的token值,在请求数据的时候浏览器报错如下: Request header field Authorization is not allowed by Access-Control-Allow-Headers 解决办法就是让后台将‘Authorization ’添加到‘Access-Control-Allow-Headers’中. 后来查资料发现问题跟跨域请求有关
API axios.js import axios from "axios"; let AUTH_TOKEN=(function(){ return localStorage.getItem("token"); })(); var instance = axios.create({ }); instance.defaults.headers.common["Authorization"] = AUTH_TOKEN; instance.interc
import axios from "axios"; import qs from "qs"; //处理参数 import router from '../router'; import { Loading } from 'element-ui'; import { Message } from 'element-ui'; let loading = null; //开始加载动画 function openLoading(){ loading = Loading.s