Autodesk OA 面试真题:Login Form Exercise 表单登录与接口调用

28次阅读
没有评论

Login Form Exercise

This is an incomplete login form.

Do not add any additional HTML elements.

The login() service works as follows:

  • Accepts an email and password, returns a JSON response containing either a token if successful or an error if there is an issue.

Examples:

  • Valid email address (any password is valid): emma.wong@reqres.in, returns {"token":"QpwL5tke4Pnpja7X3"}
  • Invalid email address, returns {"error":"user not found"}

Tasks:

  • The login button should trigger the login service.
  • Show an error message from the login service.
  • Clear the error message every time the user re-attempts login.
  • Show an alert box (native Javascript alert) on successful login.

这道题考察的是前端登录表单的交互处理:点击登录按钮后调用给定的 <code>login()</code> 接口,根据返回结果分别展示错误信息或成功弹窗,并且在用户再次提交时清空旧的错误提示。题目强调不要额外添加 HTML 元素,说明实现应尽量在现有表单结构内完成状态管理、异步请求和反馈展示。核心在于正确处理表单提交、接口返回的 <code>token</code> / <code>error</code> 分支,以及重复尝试时的状态重置。

正文完
 0