Firebase + Vue.js中的updateProfile()

时间:2018-06-20 10:06:36

标签: firebase firebase-authentication

我有一些类似的功能:

var s = new Vue({
  el: "#sPage",
  data: {
    email: '',
    password: '',
    confirmPassword: '',
    displayName: ''
  },
  methods: {
    createAccount: function() {

      if (this.password.length < 6) {
        alert('Password must contain more than 6 characters')
        return
      }
      if (this.password != this.confirmPassword) {
        alert('Confirm password not match')
        return
      }

      firebase.auth().createUserWithEmailAndPassword(this.email, this.password).then(() => {
        user = firebase.auth().currentUser;
        console.log(this.displayName)
        user.updateProfile({
           displayName: this.displayName
        });
          }).catch(function(error) {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            if (errorCode == 'auth/weak-password') {
              alert('The password is too weak')
            } else {
              alert(errorMessage)
            }
            console.log(error)
          })
          alert('Register success')
          this.email = ''
          this.password = ''
          this.confirmPassword = ''
          this.displayName = ''
        }
    }

在这一行:

  user = firebase.auth().currentUser;
        console.log(this.displayName)
        user.updateProfile({
          displayName: this.displayName
        });

当我使用console.log(this.displayName)时this.displayName的值显示空白值 enter image description here

我的表格:

<input v-model="displayName" type="text" placeholder="Display Name" />

如何获取与displayName绑定的实际值 谢谢

0 个答案:

没有答案