【问题标题】:v-rating not displaying the value stored in the firestore databasev-rating 不显示存储在 Firestore 数据库中的值
【发布时间】: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


    【解决方案1】:

    您正在使用 item-value="rating"。据我所知,它的 value="5" 和绑定它应该是 :value="item.rating" 尝试改变它。如果您没有对每个项目进行评分,请务必检查。

    【讨论】:

    • 嗨!现在可以使用了 :)) 是的,将 item-value="rating" 更改为 :value="item.rating" 确实解决了问题,我现在可以在星级评分中显示该值。谢谢!
    猜你喜欢
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-06
    相关资源
    最近更新 更多