提交表单后如何传递登录失败错误?

时间:2020-05-01 19:59:50

标签: reactjs axios

我有一个用reactJS编写的登录组件,它使用axios执行登录端点。如果由于有效原因登录失败,我将loginerror保存为状态。然后,我在JSX的返回部分中有一个div标签,该标签应该显示错误。但是,不会显示此消息。我了解JSX会在异步调用完成之前运行。我该如何解决该问题?

--with-includes=DIRECTORIES

    "DIRECTORIES" is a colon-separated list of directories that will
    be added to the list the compiler searches for header files. If
    you have optional packages (such as GNU Readline) installed in a
    non-standard location, you have to use this option and probably
    also the corresponding "--with-libraries" option.

    Example: --with-includes=/opt/gnu/include:/usr/sup/include.

--with-libraries=DIRECTORIES

    "DIRECTORIES" is a colon-separated list of directories to search
    for libraries. You will probably have to use this option (and
    the corresponding "--with-includes" option) if you have packages
    installed in non-standard locations.

    Example: --with-libraries=/opt/gnu/lib:/usr/sup/lib.

1 个答案:

答案 0 :(得分:0)

this.state.state.loginError应该是this.state.loginError

此外,axios返回的错误不是简单的消息,而是对象。

如果要显示某些内容,则需要访问其中的属性。因此应该是this.state.loginError.response.message或只是将原始状态设置为邮件

检查引荐来源:https://github.com/axios/axios#handling-errors