Uncaught (in promise) Error: Network Error at createError(axios跨域问题)
Uncaught (in promise) Error: Network Error at createError(axios跨域问题)
axios请求到了数据但then返回不到数据,这是由于vue前端访问地址出现的跨域问题。
1、如果你是自己写的后端,可以添加配置类来避免跨域问题(建议使用)

package com.ftest.springboot.config;
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 CrosConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.allowCredentials(true)
.allowedHeaders("*")
.maxAge(3600);
}
}
这样就不用担心跨域了!


浙公网安备 33010602011771号