Vue axios cross domain request cannot be solved with cookie

  • 2021-08-12 01:56:02
  • OfStack

Set in main. js

//Carrying cookie

axios.defaults.withCredentials = true

Additional knowledge: VUE axios does not bring cookie when requesting cross-domain or changes cookie every time

When writing the management backend with VUE in the past two days, I encountered a wonderful problem:

When I use dev configuration development locally, the request can be packaged with cookie information and deployed on the server, but the request does not bring cookie information.

Then check it slowly, and unite with back-end colleagues to check this cookie problem. The front end is also configured

axios.defaults.withCredentials = true;

The backend is also configured with cross-domain cookie, and then it is useless. Every time the backend obtains sessionID, it is a new one.

Well, after carefully comparing the cross-domain related configurations, I found that there was really nothing wrong with this one, so I started to check the tools introduced by VUE project.

After checking one by one, I finally found something that is a demon: mock. js

Due to configuration problems, when packaging and deploying, mock was introduced into packaging, and mock refreshed cookie of each request, resulting in different SessionID obtained in the background every time.

Well, who is to blame for writing your own code?


Related articles: