【发布时间】:2021-11-14 20:54:37
【问题描述】:
在这里需要一些帮助。我想创建一个承包商的绩效评级,我们可以使用 vuetify v-rating 对承包商进行评级并将其保存到 firebase firestore。
我成功更新评级并将其保存在 Firestore 中,但每当我刷新页面时,它会显示一个空的评级槽,例如 rating slot is empty after refresh,即使它存储在 Firestore 中,也没有显示我刚刚键入的评级.
如果我希望它显示为数字,它确实会显示,如下所示:it shows the rating value if display it as a number.
如何以星级本身的形式显示?
<template>
<div>
<v-data-table
dense
:headers="headers"
:items="subwork"
:loading="loading"
class="elevation-1"
style="margin: 3%;">
<template v-slot:[`item.rating`]="{ item }">
<v-rating
color="yellow"
half-increments
@input="giveRating(item, $event)"
item-value="rating"></v-rating>
</template>
<template v-slot:no-data>
<v-btn color="primary" @click="initialize"> Reset </v-btn>
</template>
</v-data-table>
</div>
</template>
加载文档并将评级添加到 Firestore
methods: {
initialize() {
this.loading = true
this.subwork = []
firestore
.collection('registersubwork')
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
this.subwork.push({ ...doc.data(), id: doc.id, })
this.loading = false
})
console.log(this.subwork)
})
},
giveRating(item, value) {
this.editedIndex = this.subwork.indexOf(item);
this.editedItem = Object.assign({}, item);
console.log(item, value)
if (this.editedIndex > -1) {
Object.assign(this.subwork[this.editedIndex], this.editedItem);
} else {
this.subwork.push(this.editedItem);
}
var data = {
rating: this.editedItem.rating,
};
firestore
.collection("registersubwork")
.doc(this.editedItem.id)
.set({ rating: value }, { merge: true })// .update(data)
.then(() => {
console.log("Rating updated succesfully!");
})
.catch(e => {
console.log(e);
});
},
},
谢谢!
【问题讨论】:
标签: vue.js google-cloud-firestore nuxt.js vuetify.js