【发布时间】:2021-04-28 13:20:19
【问题描述】:
我在实际操作中从 vuex 操作参数访问数据时遇到了一些问题。可能有更好的方法来做我想做的事情,但目前获取子集合所在的 doc id 的唯一方法是将其传递到 action 参数中。
这样做,我收到一条错误消息:“FirebaseError: Function CollectionReference.doc() 要求其第一个参数的类型为非空字符串,但它是:未定义”
当我在控制台中检查带有 Vue 扩展的组件中的 Vue 数据时,需求.id 在那里:
demandId:"AE5ba0IB1aCwlYDs42ir"
所以也许我得到了这个错误,因为 demandId 是字符串类型?在这一点上,我不确定在哪里寻找答案,也许有人可以指导我通过可能的解决方案?
Vue 组件:
props: ["demand", "modalId"],
data() {
return {
meetingForm: {
demandId: this.demand.id,
status: "pending",
date: "",
time: "",
duration: null,
note: ""
}
}
},
//method:
submitModal(closeCallback) {
const meeting = {
demandId: this.meetingForm.demandId,
status: "Pending",
date: this.meetingForm.date,
time: this.meetingForm.time,
duration: this.meetingForm.duration,
note: this.meetingForm.duration
};
// Dispatch action to create Meeting in DB
this.$store
.dispatch("meetings/createMeeting", meeting)
.then(_ => {
closeCallback();
this.$toasted.success("Meeting has been succesfully created!", {
duration: 3000
});
})
.catch(e => console.error(e));
}
Vuex 操作:
createMeeting( meeting) {
meeting.createdate = Timestamp.fromDate(new Date())
const demandId = meeting.demandId
console.log(demandId)
return db
.collection('demands')
.doc(this.demandId)
.collection('meetings')
.add(meeting)
},
【问题讨论】: