springboot和vue通信解决跨域问题
springboot中添加跨域配置
@Configuration
public class Crosconfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.maxAge(3600)
.allowCredentials(true);
}
}
修改配置
main.js中写好请求前缀
Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://localhost:8081/'
axios发请求
methods: {
getUserList () {
this.$http.get('/user/1').then(response => {
console.log(response)
})
}
}

浙公网安备 33010602011771号