vue.js - v-rating 不显示存储在 Firestore 数据库中的值
问题描述
这里需要一点帮助。我想创建一个承包商的绩效评级,我们可以使用 vuetify v-rating 对承包商进行评级并将其保存到 firebase firestore。
我成功更新了评级并将其保存在 Firestore 中,但是每当我刷新页面时,它会显示一个空的评级槽,例如刷新后这个评级槽是空的,即使它存储在 Firestore 中,也没有显示我刚刚键入的评级.
如果我希望它显示为数字,它会显示,如下所示:如果将其显示为数字,它会显示评级值。
如何以星级本身的形式显示?
<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);
});
},
},
谢谢!
解决方案
您正在使用 item-value="rating"。据我所知,它的 value="5" 和绑定它应该是 :value="item.rating" 尝试改变它。如果您没有对每个项目进行评级,请务必检查。
推荐阅读
- python - 是否有任何适用于 sqlite(用于测试)和 mysql(用于生产)的 sqlalchemy 列表插值语法?
- javascript - 仅 Aframe 广告牌 Y 轴
- nginx - 乘客 sub uri's
- android - 具有有界类型参数的通用 BaseFragment 架构以与 ViewModel 一起使用
- android - Flutter:如何使 Listview 中的 TextView 填充剩余空间
- node.js - 通过 Slack API 上传远程文件
- google-cloud-platform - Google Cloud Run 只能访问 http://metadata.google.internal 上的元数据子集
- android - android应用程序没有显示带有真实ID的广告
- c - 一个八进制转十进制的c程序
- angular - 使用公共参数将 ID 从一个集合拉到另一个集合