Skip to content

Console:看报错和运行代码

第一次操作

  1. Mac 按 ⌘ + Option + J,Windows 按 Ctrl + Shift + J
  2. 如果看到很多信息,先点左上角“禁止符号”或 Clear console 清空。
  3. 找到最下面的 >,点击它。
  4. 输入 document.title 并回车。
  5. 看到当前网页标题,说明 Console 成功读取了页面。

红色不等于世界末日

一条报错通常这样读:

text
Uncaught TypeError: Cannot read properties of undefined
    at App.tsx:58:12

先点 App.tsx:58:12,它表示文件、第 58 行、第 12 列。再看 undefined 前后在读取哪个字段。不要从整页代码第一行开始猜。

在本站试一次

把下面代码复制到 Console:

js
document.querySelector('#practice-card')

如果当前页面没有这个元素,会得到 null;去 Elements 练习页 再运行,就会看到真实的 <div>

Console 里得到 null 一定表示网站坏了吗?

答案:不一定。它可能只表示当前页面没有匹配到这个元素,先检查选择器和所在页面。

写给想驾驭 AI,而不只是依赖 AI 的 Vibe Coder。