亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無服務器:“errorMessage”:“無法讀取未定義的屬性 'id'”,

無服務器:“errorMessage”:“無法讀取未定義的屬性 'id'”,

Smart貓小萌 2022-10-13 16:00:49
我開始嘗試用 node 和 puppeteer 編寫一個 lambda 函數。我正在使用無服務器框架。在我的 handler.js 中:exports.detail = async (event, context) => {  console.log(event);  let id = event.pathParameters.id || 1;  console.log(id);我一直在嘗試使用 event 參數傳入 id 參數,但如果未設置,我希望將值設置為 1 。但是當我嘗試時:$ sls invoke local -f detail {"errorMessage": "Cannot read property 'id' of undefined","errorType": "TypeError","stackTrace": [    "TypeError: Cannot read property 'id' of undefined",我怎樣才能得到這個工作?
查看完整描述

1 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

event.pathParameters.id失敗是因為event.pathParameters未定義。錯誤消息告訴您undefined沒有名為id.

嘗試:

let id = event.pathParameters ? event.pathParameters.id : 1;

反而


查看完整回答
反對 回復 2022-10-13
  • 1 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號