跨域
这样无非百分百就是跨域 跨域自己百度即可
然后我们如何解决 后端是可以设置的:
前段代码:
引入axios ,使用axios:
后端:
直接一个配置类带走 ,其实就是
WebMvcConfigurer 然后
addCorsMappings
下面一顿骚炒作自己百度即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package com.bihu.study.Config; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOriginPatterns("*") .allowedHeaders(CorsConfiguration.ALL) .allowedMethods(CorsConfiguration.ALL) .allowCredentials(true) .maxAge(3600); //一小时内不需要再预检(发OPTIONS请求) } }
最后: