You need to enable JavaScript to run this app. React提交注册表单时出现无法读取undefined的data属性报错
优惠活动
大模型
产品
解决方案
定价
更多

React提交注册表单时出现无法读取undefined的data属性报错

问题现象
  • 项目中触发注册提交操作(填写姓名、邮箱、密码后提交)时,持续抛出Unhandled Rejection (TypeError): Cannot read property 'data' of undefined报错,经初步排查未定位到问题根源。
  • 已完成前置校验:对应后端接口服务运行正常,排除服务端宕机、不可用的问题。
  • 参考材料:附React项目运行时的报错界面截图。
待排查的前端提交逻辑代码
const clickSubmit = (event) => {
    event.preventDefault();
    setValues({ ...values, buttonText: 'Submitting' });
    axios({
        method: 'POST',
        url: `${process.env.REACT_APP_API}/signup`,
        data: { name, email, password },
    })
        .then((response) => {
            console.log('SIGNUP SUCCESS', response);
            setValues({
                ...values,
                name: '',
                email: '',
                password: '',
                buttonText: 'Submitted',
            });
            toast.success(response.data.message);
        })
        .catch((error) => {
            console.log('SIGNUP ERROR', error.response.data);
            setValues({ ...values, buttonText: 'Submit' });
            toast.error(error.response.data.error);
        });
};

内容的提问来源于stack exchange,提问作者Jose E. Rodriguez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.18 17:36:09