这个问题通过字面意思,可以看出来是跨域问题,这个是去检查前后端代码,是不是跨域没有设置好, 比如我这次后端的没有弄好,所以就报这种错误。 如果是vue的话,就可以如下方式
module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api':{ target:'http://localhost:8443', //后期可以改 changeOrigin:true, pathRewrite:{ '^/api': '' } } }, //配置跨域支持
springboot的话,如果没有config层的话,建议做一个,然后在里面编写一个java文件,参考如下,实现全局跨域.
@SpringBootConfigurationpublic class MyWebConfigurer implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry corsRegistry){ /** * 所有请求都允许跨域,使用这种配置就不需要 * 在interceptor中配置header了 */ corsRegistry.addMapping("/**") .allowCredentials(true) .allowedOrigins("http://localhost:8080") .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") .allowedHeaders("*") .maxAge(3600); }