【发布时间】:2021-07-04 00:03:33
【问题描述】:
大家好,我遇到了一个问题,我的数据被改回原来的分配。例如,我有以下数据:
data() {
return {
uid: "",
pic: "hello",
}
},
使用下面的函数,警报返回“hello”
created() {
this.uid = fb.auth().currentUser.uid;
this.getprofilepic();
},
** getprofilepic 函数
getprofilepic() {
fb.storage().ref('users/' + this.uid + '/profile.jpg').getDownloadURL().then(imgurl => {
this.pic = imgurl;
})
alert(this.pic); // returns "hello"
},
如果我将警报放入 fb.storage...,它会返回正确的路径,如下所示:
getprofilepic() {
alert("getting profile pic")
fb.storage().ref('users/' + this.uid + '/profile.jpg').getDownloadURL().then(imgurl => {
this.pic = imgurl;
alert(this.pic); // returns correct path;
})
},
是否有理由再次覆盖数据?预先感谢您的任何帮助! :) 我想 v-bind:src 从 firebase 存储中获取照片的路径,但“pic”返回“hello”。您可以在下面找到我的 html 代码:
<b-avatar :src = "pic" id = "profilepic" class="mr-5" size="8em"></b-avatar>
【问题讨论】:
-
每次特定页面再次呈现时,数据属性中的所有分配都会设置为其初始分配。
-
嗨@YashMaheshwari,感谢您的评论。你的意思是调用 fb.storage().ref.... 会刷新页面,还有没有办法解决这个问题?谢谢
标签: javascript firebase vue.js firebase-storage