Firebase+;Vue.js

Firebase+;Vue.js,firebase,firebase-authentication,Firebase,Firebase Authentication,我有一些功能,比如: var s = new Vue({ el: "#sPage", data: { email: '', password: '', confirmPassword: '', displayName: '' }, methods: { createAccount: function() { if (this.password.length < 6) { alert('Password m

我有一些功能,比如:

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 = ''
        }
    }
当我使用console.log(this.displayName)时,this.displayName的值显示为空值

我的表格:

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

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

这很难,因为您在问题中显示的代码很难知道为什么会出现这种情况。displayName在`CreateCount方法中为空。一个简单而“愚蠢”的问题:在调用该方法之前是否在字段中手动输入值?另一个注释:由于
createUserWithEmailAndPassword(电子邮件,密码)
返回包含
firebase.auth.UserCredential
的承诺,如文档中所述,您应该能够使用
userCredential获取用户。当我使用getElementById('buttonID')获取插入到@RenaudTarnec表单中的displayName值时,用户可以添加它。现在我的问题是如何获得绑定到表单的这个.displayName值从表单输入绑定的角度来看,您的代码似乎是正确的。如果您为
this.email
this.password
获得了正确的值,那么如果填写了这三个字段,您还应该为
this.displayName
获得一个值。箭头函数是否可以使用外部变量@雷纳德塔内克
<input v-model="displayName" type="text" placeholder="Display Name" />