axios跨域问题

VUE@axios跨域问题:

package com.dfec.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 
 */
@Component
public class GlobalInterceptor implements HandlerInterceptor {

    private final Logger logger = LoggerFactory.getLogger(ProcessInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        response.setHeader("Access-Control-Allow-Origin", "*");
        //*表示允许所有域名跨域
        response.addHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");
        //允许跨域的Http方法
        response.addHeader("Access-Control-Allow-Methods", "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,PATCH");
        response.addHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");
        response.addHeader("Access-Control-Allow-Credentials","true");
        response.addHeader("Access-Control-Max-Age", "0");
        response.addHeader("XDomainRequestAllowed","1");
        return true;
    }
}

 

你可能感兴趣的:(Error)