【发布时间】:2020-01-10 08:26:32
【问题描述】:
我想从 Firestore OnSnapshot 函数返回值,以便我可以检索用户图像的 url。我正在使用 vuejs 和 firestore。我在 vue 的 created 属性中有 activeUserImg 函数。
activeUserImg: function () {
const u = firebase.auth().currentUser;
firebase.firestore().collection('Colleges').doc(u.uid).onSnapshot(function(doc) {
var img_arr=[];
this.img_arr.push(doc.data())
this.img= doc.data().logo
});
return this.img || this.$store.state.AppActiveUser.img;
}
并且每次都将返回的值显示为未定义。
图片代码:
<img
v-if="activeUserImg.startsWith('http')"
key="onlineImg"
:src="activeUserImg"
alt="user-img"
width="40" height="40"/>
<img
v-else
key="localImg"
:src="require(`@/assets/images/portrait/small/${activeUserImg}`)"
alt="user-img"
width="40" height="40"/>
【问题讨论】:
-
你能提供你的firestore数据库的截图吗?
-
i.imgur.com/UKA4HKw.pngfirestore的截图
标签: firebase vue.js google-cloud-firestore vuex