我们可以使用Axios中的withCredentials选项来设置跨域请求时是否需要在请求中包含cookie信息。默认情况下,该选项为false,因此需要将其设置为true。
以下是示例代码:
axios.get(url, {
withCredentials: true,
}).then(response => {
console.log(response);
}).catch(error => {
console.log(error);
});
在上面的代码中,我们将axios的get请求中的withCredentials选项设置为true,这将允许请求在跨域请求时携带cookie。