文章目录
- reference link
- 使用 [DevTools]进行调试
- 检查项目中的package.json
- 找到连接直接打开(推荐)
- yarn 方式
- npm 方式
- 打开控制台选项卡
- vscode debug
- 配置F5启动调试
- 创建 launch.json
- ctx.body
reference link
(eggjs.org)
使用 [DevTools]进行调试
检查项目中的package.json
找到连接直接打开(推荐)
yarn 方式
yarn debug
(我这里配置了powershell别名y->yarn
)
npm 方式
npm run debug
打开控制台选项卡
vscode debug
for vscode: (eggjs.org)
配置F5启动调试
创建 launch.json
直接在.vscode
中创建一个launch.json
,并写入一下内容:(F5)启动调试
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Egg",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"windows": {
"runtimeExecutable": "npm.cmd"
},
"runtimeArgs": [
"run",
"debug"
],
"console": "integratedTerminal",
"protocol": "auto",
"restart": true,
"port": 9229,
"autoAttachChildProcesses": true
}
]
}
关于配置里的端口,应该避免和当前的被占用的端口号重合,或者调试前关闭其他端口
ctx.body
该属性默认值为undefined
经过赋值后,浏览器可以渲染出对应的内容
在使用ctx.body+="append"的时候,需要注意,不应该一开始就使用+=
;至少有一个非unfined
值被明确赋值给ctx.body
后才可以用+=
追加内容