Firebase 函数重新加载身份验证当前用户,在 vue 组件中不刷新



我正在使用函数reload更新配置文件url,我有一个计算的属性,但这不能反映的变化

计算属性

computed: {
photoUrl: function() {
return firebase.auth().currentUser.photoURL;
},
}

功能

onFileChanged: async function(e) {
this.image = e.target.files[0];
if (this.image) {
try {
this.loading = true;
const url = await saveImage(this.image, this.uploadProgress);
await auth.currentUser.updateProfile({
photoURL: url
});
await auth.currentUser.reload();
} catch (error) {
this.setTexto("Ocurrió un error al actualizar tu foto de perfil.");
this.setColor("error");
this.setVisible(true);
console.error(error);
} finally {
this.progreso = 0;
this.loading = false;
}
}
}

我正在使用firebase云存储上传文件作为承诺。

一种选择是在data对象中有一个简单的属性,并在函数中更新它,如下所示:

data: {
//....
photoUrl: null,
//....
}
//...
onFileChanged: async function(e) {
this.image = e.target.files[0];
if (this.image) {
try {
this.loading = true;
const url = await saveImage(this.image, this.uploadProgress);
this.photoUrl = url;  // <-------
await auth.currentUser.updateProfile({
photoURL: url
});
await auth.currentUser.reload();
} catch (error) {
//...
} finally {
//...
}
}
}

最新更新