【发布时间】:2020-08-24 15:29:50
【问题描述】:
我正在尝试使用来自 Firestore 的一些数据。在它以前工作之前,现在在 Vuetify 中,如果我尝试访问 $data.users,我会一直收到“PENDING”
export default {
data() {
return {
users: [],
};
},
created() {
db.collection('users').get().then((snapshot) => {
snapshot.forEach((doc) => {
const user = doc.data();
user.id = doc.id;
this.users = user;
console.log(user.documents.selfie.url); // Here the log return the value correctly
});
});
},
methods: {
imageUrl(user) {
console.log(user.documents.selfie.url); // Here the log return "Pending";
},
在模板中我运行v-for (user, index) in users :key='index'
错误:
Uncaught (in promise) TypeError: Cannot read property 'selfie' of undefined
【问题讨论】:
-
在 v-for 检查之前 v-如果您的数据已设置并使用
user.documents.selfie.url || 'http://example.com/to/default.jpg'
标签: firebase vue.js google-cloud-firestore vuetify.js