首页 > 解决方案 > TypeError:无法读取未定义的属性“FieldValue”

问题描述

  19 | event.preventDefault();
  20 | db.collection('todos').add({
  21 |   todo:input,
  22 |   timestamp: firebase.firestore.FieldValue.serverTimestamp()
  23 |  });
  24 | 
  25 | setInput("");

每当我尝试运行此代码时,它都会显示类型错误。这样我就无法将数据推送到 Firebase

标签: javascriptreactjsfirebase

解决方案


确保您具有正确的timestamp值,或者如果您不需要它们,请不要传递时间戳。尝试将此 json 传递给 todos 集合:

{
  todo:input,
  timestamp: firebase.firestore.FieldValue.serverTimestamp() || null
}

通过登录并尝试确保您在FieldValue里面firebase.firestoreconsole.log(firebase.firestore)console.log(Object.keys(firebase.firestore))


推荐阅读