前后端分离开发时,vue使用axios请求后台接口失败

前后端分离开发,Vue+Springboot

Vue使用axios发送请求到后台接口无反应,F12查看network–>发现请求没有类型和状态

解决方案:

后台启动类中添加addCorsMappings:


public class DataManagementApplication extends WebMvcConfigurerAdapter{

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowCredentials(true).allowedHeaders("*").allowedOrigins("*").allowedMethods("*");
    }
    public static void main(String[] args) {
        SpringApplication.run(DataManagementApplication.class, args);
    }

}



Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐