跨域问题,改了配置后依然报404找不到

一、开发环境(打包后此方式失效)

前后端分离,vue项目使用后台接口渲染数据时,在这里插入图片描述跨域问题

使用proxy代理中间件解决跨域问题,改了配置后依然报404找不到,是因为:
在这里插入图片描述
这里不是

localhost

!!!!
要改成本机ip

二、nginx代理

三、接口允许跨域

新建配置类,代码如下,直接拷贝粘贴即可

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CrossConfig implements WebMvcConfigurer {
  	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**").allowedOriginPatterns("*").allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
				.allowCredentials(true).maxAge(3600).allowedHeaders("*");
	}
}


版权声明:本文为weixin_42707397原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。