前后端开发学习中,vue里面需要跨域访问后台数据

可在springboot后台里面添加个配置类即可:

 

package com.springboottest.config;

import org.springframework.beans.factory.annotation.Configurable;
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("/**")
                .allowedOrigins("*")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2021-08-13
  • 2021-09-14
  • 2021-06-19
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案