bug-1 umi.js service.js 请求接口没有引入 get/post

what - bug

图片.png请求出现上述情况

why - 原因

写接口时,没有引入 post…

  1. import { post } from '@/services/httpServer'

how - 解决

检查/打印 接口

bug-2 umi.js service.js 请求时,缺失 /

what - bug

请求时 出现 Uncaught (in promise) <!DOCTYPE html> 如下

try{} catch(error) {console.error(error)} 请求接口的代码时,发现请求的接口无效

  1. Uncaught (in promise) <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta
  7. name="keywords"
  8. content="antd,umi,umijs,ant design,Scaffolding, layout, Ant Design, project, Pro, admin, console, homepage, out-of-the-box, middle and back office, solution, component library"
  9. />
  10. <meta
  11. name="description"
  12. content="
  13. An out-of-box UI solution for enterprise applications as a React boilerplate."
  14. />
  15. <meta
  16. name="description"
  17. content="
  18. Out-of-the-box mid-stage front-end/design solution."
  19. />
  20. <meta
  21. name="viewport"
  22. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
  23. />
  24. <title>Ant Design Pro</title>
  25. <link rel="icon" href="./favicon.ico" type="image/x-icon" />
  26. <script
  27. type="text/javascript"
  28. src="https://api.map.baidu.com/api?v=3.0&amp;ak=7ZSAUpGq9b8j5aKXCB3B6aglOi2iTlKX"
  29. ></script>
  30. <script>
  31. window.BMap = BMap;
  32. </script>
  33. <script>
  34. window.routerBase = "/";
  35. </script>
  36. <script src="./@@/devScripts.js"></script>
  37. <script>
  38. //! umi version: 3.5.20
  39. </script>
  40. <script>
  41. !(function () {
  42. var e = localStorage.getItem("dumi:prefers-color"),
  43. t = window.matchMedia("(prefers-color-scheme: dark)").matches,
  44. r = ["light", "dark", "auto"];
  45. document.documentElement.setAttribute(
  46. "data-prefers-color",
  47. e === r[2] ? (t ? r[1] : r[0]) : r.indexOf(e) > -1 ? e : r[0]
  48. );
  49. })();
  50. </script>
  51. </head>
  52. <body>
  53. <noscript>Out-of-the-box mid-stage front/design solution!</noscript>
  54. <div id="root"></div>
  55. <script src="./umi.js"></script>
  56. </body>
  57. </html>

why - 原因

后端给接口时,没有复制完整,复制时 certification/machine/getProjectMachineModel
缺失了 / ,导致上述报错
图片.png

how - 解决

使用 try...catch 检查 接口请求处的代码,如果 try 中的代码块执行没有反应,说明是接口的问题
需要检查 service.js 中的接口:
查看1 - 是否忘记引入 get / post
查看2 - 接口路径,是否缺失/,或者 是否使用了错误的路径