在Axios的请求配置中添加config属性并设置为{ withCredentials: true }。这将为请求启用cookie,并在服务器响应时携带响应的cookie,以便在发送进度事件时验证身份。
示例代码:
axios.post(url, formData, { onUploadProgress: function(progressEvent) { // handle progress event }, config: { withCredentials: true } }) .then(function(response) { // handle response }) .catch(function(error) { // handle error });