web前端

vue egg 前后端分离 cookies 跨域设置

2019-03-12  本文已影响0人  并入高黄

egg 设置

1. 下载跨域插件 egg-cors
2. 在plugin.js 配置
exports.cors = {
  enable: true,
  package: 'egg-cors',
};
3.config.default.js 配置跨域
config.cors = {
  origin:'http://localhost:9999',   // 跨域设置cookios 不能设为 *
  credentials: true,
  allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
};
4. 设置 ctx.cookies.set('count','aaa');
5. 获取 ctx.cookies.get('count');

vue 设置

axios 设置

const service = axios.create({
 withCredentials: true,
 crossDomain: true
});
上一篇 下一篇

猜你喜欢

热点阅读