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:配置可以被跨域