关于nuxt服务端渲染 axios跨域请求每次sessionid都不一样的处理方式:
- axios设置withCredentials为true.
- 提供接口的服务器需设置跨域
corsConfiguration.addAllowedOrigin("");
corsConfiguration.addAllowedHeader("");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setMaxAge(3600l); //这里是3600,只是因为本程序这里需要long类型参数所以加了一个L
corsConfiguration.setAllowCredentials (true); - 关于withCredentials的解释:https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/withCredentials
- 这里要感谢昆虫大侠的一片文章:https://my.oschina.net/alyouge/blog/1930452?from=singlemessage
本文介绍了在使用Nuxt进行服务端渲染时,如何通过设置axios的withCredentials属性及提供接口的服务器配置cors来确保每次跨域请求的sessionID保持一致,避免因sessionID变化导致的请求失败问题。
3358





