解決SpringBoot Vue 跨域問題

一、報(bào)錯內(nèi)容如下:

Failed to load http://192.168.1.111:8888/console/good/front/classList: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8081’ is therefore not allowed access. If an opaque response serves your needs

二、在后臺添加如下文件


@Configuration

public class MvcConfigimplements WebMvcConfigurer {

@Override

? ? public void addCorsMappings(CorsRegistry registry) {

// 這里匹配了所有的URL,允許所有的外域發(fā)起跨域請求,允許外域發(fā)起請求任意HTTP Method,允許跨域請求包含任意的頭信息。

? ? ? ? registry.addMapping("/**")

.allowedHeaders("*")

.allowedMethods("*")

.allowedOrigins("*")

.allowCredentials(true);

}

}


即可解決,當(dāng)然也可以在nginx設(shè)置

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容