在 Axios/Fetch 请求时需要添加“withCredentials”字段并设置为“true”,才能在浏览器中设置 cookie。
以下是 Axios 和 Fetch 的示例代码:
使用 Axios:
axios.get('/api/user', { withCredentials: true })
使用 Fetch:
fetch('/api/user', { credentials: 'include' })
上一篇:Axios/Fetchnotusingnext.config.jsrewrite
下一篇:axios/fetch在使用PHPAPI时失败,但是postman能够正常工作。