bug-1 umi.js service.js 请求接口没有引入 get/post
what - bug
why - 原因
写接口时,没有引入 post…
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)} 请求接口的代码时,发现请求的接口无效
Uncaught (in promise) <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><metaname="keywords"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"/><metaname="description"content="An out-of-box UI solution for enterprise applications as a React boilerplate."/><metaname="description"content="Out-of-the-box mid-stage front-end/design solution."/><metaname="viewport"content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/><title>Ant Design Pro</title><link rel="icon" href="./favicon.ico" type="image/x-icon" /><scripttype="text/javascript"src="https://api.map.baidu.com/api?v=3.0&ak=7ZSAUpGq9b8j5aKXCB3B6aglOi2iTlKX"></script><script>window.BMap = BMap;</script><script>window.routerBase = "/";</script><script src="./@@/devScripts.js"></script><script>//! umi version: 3.5.20</script><script>!(function () {var e = localStorage.getItem("dumi:prefers-color"),t = window.matchMedia("(prefers-color-scheme: dark)").matches,r = ["light", "dark", "auto"];document.documentElement.setAttribute("data-prefers-color",e === r[2] ? (t ? r[1] : r[0]) : r.indexOf(e) > -1 ? e : r[0]);})();</script></head><body><noscript>Out-of-the-box mid-stage front/design solution!</noscript><div id="root"></div><script src="./umi.js"></script></body></html>
why - 原因
后端给接口时,没有复制完整,复制时 certification/machine/getProjectMachineModel
缺失了 / ,导致上述报错
how - 解决
使用 try...catch 检查 接口请求处的代码,如果 try 中的代码块执行没有反应,说明是接口的问题
需要检查 service.js 中的接口:
查看1 - 是否忘记引入 get / post
查看2 - 接口路径,是否缺失/,或者 是否使用了错误的路径
请求出现上述情况
