axios请求带cookie

axios请求默认不带cookie

axios默认是发送请求的时候不会带上cookie的,这导致当服务器使用session来保存登录态时,客户端永远无法登陆的情况。

1
2
3
import axios from 'axios'; // 引入axios

axios.defaults.withCredentials = true; // 允许携带cookie

这样即可解决

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2015-2021 AURORA_ZXH
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信