可能的原因之一是未正确配置表单数据对象。确保您的FormData对象具有需要发送到后端的正确键和值。以下是一个示例:
const formData = new FormData(); formData.append('username', 'John'); formData.append('password', 'Doe');
然后,您可以通过Axios将该表单数据对象发送到后端:
axios.post('/api/login', formData) .then(response => { console.log(response); }) .catch(error => { console.log(error); });
如果您的FormData表单数据对象正确配置,但仍然发送为空值,请检查后端代码以确保正确解析FormData对象。
上一篇:axios封装在catch块中抛出200成功响应而不是then块中,如何解决?
下一篇:axios给我报错(POST /api/v1/users/token/refresh/ HTTP/1.1" 401 65),如何解决?