Spring Boot和Vue跨域請求問題原理解析
更新時間:2019年12月02日 10:57:10 作者:咸魚加點鹽
這篇文章主要介紹了Spring Boot和Vue跨域請求問題原理解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
這篇文章主要介紹了Spring Boot和Vue跨域請求問題原理解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
使用Spring Boot + Vue 做前后端分離項目搭建,實現(xiàn)登錄時,出現(xiàn)跨域請求
Access to XMLHttpRequest at 'http://localhost/open/login' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Vue中使用的Axios,配置main.js文件
Axios.defaults.baseURL = 'http://localhost:80' Axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' Axios.defaults.withCredentials = true
Spring Boot中重寫WebMvcConfigurationSupport的方法addCorsMapping
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport{
@Override
public void addCorsMappings(CorsRegistry registry) {
String[] origins = {"http://localhost:8080"};
registry.addMapping("/**")
.allowedOrigins(origins)
.allowCredentials(true)
.allowedMethods("*")
.allowedHeaders("*")
.maxAge(3600);
}
}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Spring Boot中快速操作Mongodb數(shù)據(jù)庫指南
這篇文章主要給大家介紹了關于Spring Boot中如何快速操作Mongodb的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-05-05
Windows下 IDEA編譯調(diào)試 hive2.3.9的過程解析
這篇文章主要介紹了Windows下 IDEA編譯調(diào)試 hive2.3.9的過程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07
Spring Cloud應用實現(xiàn)配置自動刷新過程詳解
這篇文章主要介紹了Spring Cloud應用實現(xiàn)配置自動刷新過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-12-12

