开发uniapp时遇到前端请求后端时报错:
Access to XMLHttpRequest at ‘http://192.168.203.168:8600/login’ from origin ‘http://localhost:8081’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://192.168.203.168:8600/login with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
解决方法是在服务器端设置Access-Control-Allow-Origin**
两种全局配置方法:两种选一种即可
第一种:
@Configuration
@EnableWebMvc
public class WebMvc