1. 程式人生 > >No 'Access-Control-Allow-Origin' header is present on the requested (前段vue訪問springboot跨域報錯)

No 'Access-Control-Allow-Origin' header is present on the requested (前段vue訪問springboot跨域報錯)

做前端H5的時候。請求另外一個伺服器上的資料。用抓包工具發現已經請求成功,且有資料返回。但是在谷歌F12開啟之後。發現沒有返回;且報錯No 'Access-Control-Allow-Origin' header is present on the requested 。經檢視部落格。發現解決方法

 

public class Application extends WebMvcConfigurerAdapter {
 
    @Override
    public void addCorsMappings(CorsRegistry registry) {
 
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedHeaders("*")
                .allowedOrigins("*")
                .allowedMethods("*");
 
    }

在啟動類application中修改這樣之後。就可訪問成功。

來源:https://blog.csdn.net/qq779446849/article/details/53102925