在這里需要一點幫助。我想創建一個承包商的業績評級,我們可以使用 vuetify v-rating 對承包商進行評級,并將其保存到 firebase firestore。
我成功地更新了評級并將其保存在Firestore中,但每當我重繪 頁面時,它顯示一個空的評級槽,就像這樣重繪 后評級槽是空的,不顯示我剛剛鍵入的評級,盡管它已存盤在Firestore中。
如果我想讓它顯示為一個數字,它確實顯示了,就像這樣。如果顯示為數字,它將顯示評級值。
如何以星級本身的形式顯示?
<template>
<div>
<v-data-table
密密麻麻的
:headers="標題"
:items="subwork"
:loading="裝載"
class="elevation-1"
style="margin: 3%;">
<模板v-slot:[`item.rating`]="{ item }">
<v-rating
color="yellow"
半遞增
@input="giveRating(item, $event)"
item-value="rating"></v-rating>
</template>
<模板v-slot:no-data>
<v-btn color="primary" @click="initialize"> Reset </v-btn>
</template>
</v-data-table>
</div>
</template>
加載檔案&添加評級到firestore
方法:{
initialize() {
this.loading = true
this.subwork = []
firestore
.collection('registersubwork')
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// doc.data()對于查詢doc快照來說永遠是未定義的
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)
如果(this.editedIndex > -1){
Object.assign(this.subwork[this.editedIndex], this.editedItem)。
} else {
this.subwork.push(this.editedItem)。
}
var data = {
rating: this.editedItem.rating,
};
火店
.collection("registersubwork")
.doc(this.editedItem.id)
.set({ rating: value }, { merge: true })// .update(data)
.then(() => {
console.log("Rating updated succesfully!")。
})
.catch(e => {
console.log(e);
});
},
},
謝謝!
uj5u.com熱心網友回復:
你在使用 item-value="rating"。據我所知,它的值是="5",對于系結,它應該是 :value="item.rating" 嘗試改變這個。如果你沒有每個專案的評級,請確保檢查。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/327374.html
標籤:
下一篇:Vuejs搜索功能不能正常作業
