springboot + element-ui + axios 跨域请求解决方案

本文介绍了如何在SpringBoot应用中结合Element-UI和AxiOS实现跨域请求的解决方案。首先,在main.js文件中设置axios的withCredentials属性为true以携带cookie。接着,详细讲解了SpringBoot的全局跨域配置步骤,适用于SpringBoot的特定版本。最后,演示了使用AxiOS发起跨域请求并成功获取资源的过程。
摘要由CSDN通过智能技术生成

1、在 main.js 文件中添加如下内容

    import axios from 'axios'

    //axios跨域设置 true跨域请求携带cookie

    axios.defaults.withCredentials = true

2、springboot编写全局跨域请求配置

     springboot版本

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath/>
  </parent>
package com.tensquare.user.config;

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 ApplicationConfig extends WebMvcConfigurationSupport {

    /**
     * 全局配置 axios 跨域请求
     * addMapping:配置可以被跨域
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值