赞
踩
1.安装axios
在项目终端下 输入
npm install axios --save
2.在main.js全局引入axios
import axios from 'axios';
Vue.prototype.$axios=axios;
3.重写WebMvcConfigurer(全局跨域)
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 CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
//是否发送Cookie
.allowCredentials(true)
//放行哪些原始域
.allowedOriginPatterns("*")
.allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"})
.allowedHeaders("*")
.exposedHeaders("*");
}
}
有用的话请点一个赞,我好统计是否对你有帮助,判断是否需要补充
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。