项目配置
- vue-cli3
- vue2
- element-ui-2.15.3
在网上找了很多方案,但是都没有生效,最后是前端添加了一段代码,后台添加了一段代码 解决了
添加了headers的配置
const instance = axios.create({
// baseURL: 'http://mall.huolida.com/',
// baseURL: '/api',
withCredentials: false, // 允许携带cookie
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
baseURL: '/api',
changeOrigin: true,//是否跨域
timeout: 100000
})
添加了header的配置
header('Access-Control-Allow-Origin: http://192.168.1.117:8080');
// 也可以添加所有的请求为 允许,当然不推荐这样做了、
header('Access-Control-Allow-Origin: *');
这样就解决了困扰我好久的跨域