![](/img/trans.png)
[英]Vue.js - Referencing input inside a modal to update Firestore database
[英]Vue.js and Firestore update only the variables that are not equal to empty string
只更新不等于空字符串的变量
const state = reactive({
birthNumber: '',
phoneNumber: '',
DoctorName: '',
DoctorPhone: '',
})
db.collection(state.user.uid).doc("Personal_Records").update({
birthNumber: state.birthNumber,
phoneNumber: state.phoneNumber,
DoctorName: state.DoctorName,
DoctorPhone: state.DoctorPhone
})
我只需要更新会改变的变量。 Firestore 仍然使用空字符串更改它们。感谢您的帮助。
使用 Firestore update()
方法时,您不需要传递文档的所有值。 只需传递新的更改值就足够了,因为update()
方法将仅更改 Firestore 文档中的此字段。 所以你需要检查你的字段是否有来自你的应用程序的值,并相应地将它们传递给update()
方法。 在此处阅读更多相关信息
您可以构建一个仅包含要更新的字段的对象,并将其传递给update()
。 您确定要在该对象上设置哪些属性。
const update = {}
if (shouldUpdateBirthNumber} {
update.birthNumber = state.birthNumber
}
// repeat for each optional field to update
db.collection(state.user.uid).doc("Personal_Records").update(update);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.