已拦截跨源请求:同源策略禁止读取位于 http://localhost:8888/api/getnews 的远程资源。(原因:CORS 头缺少 'Access-Control-Allow-Origin')。
1、主要是后端的问题,在springboot中加入下面代码即可
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**"); //对应的接口
}
};
}

本文介绍了一种解决跨源资源共享(CORS)问题的方法,特别是在SpringBoot框架中,通过配置Access-Control-Allow-Origin头部信息来允许特定的源进行跨域请求。
1372

被折叠的 条评论
为什么被折叠?



