Перезагрузка функции Firebase для auth currentUser, не обновляет sh в vue компоненте - PullRequest
0 голосов
/ 26 апреля 2020

Я использую функцию 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 в качестве обещания.

1 Ответ

0 голосов
/ 26 апреля 2020

В качестве альтернативы можно использовать простое свойство в объекте 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 {
          //...
        }
      }
    }
...