【问题标题】:VueJS Firebase Syntax errorVueJS Firebase 语法错误
【发布时间】:2019-01-13 22:49:47
【问题描述】:

我在此注册方法中找不到语法错误。现在已经一个多小时了。

.then(() => {
            db.collection("users").doc(this.slug).get().then((doc) => {

                let data = doc.data()
                db.collection("users").doc(cred.user.uid).set(data).then({
                  db.collection("users").doc(this.slug).delete()
                })

            })
          })

上面这段代码基本上是获取新创建的文档,然后将数据放入let data。之后,它使用用户 UID 创建一个新文档,因为名称将数据传递给它,然后删除旧文档。该代码中存在语法错误,但指标显示,它是 db 和 collection (db.collection) 之间的点

Error report

methods: {
    signup(){
      console.log('signup ran')
      if(this.heroName){
        this.slug = slugify(this.heroName, {
          replacement: '-',
          remove: /[$*_+~.()'"!\-:@]/g,
          lower: true
        })
        console.log(this.slug)
        let ref = db.collection('users').doc(this.slug)
        ref.get().then(doc => {
          if(doc.exists){
            this.feedback = 'This alias already exists'
          } else {
            // this alias does not yet exists in the db
            this.feedback = 'This alias is free to use'
            firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
            .then(cred => {
              ref.set({
                alias: this.heroName,
                user_id: cred.user.uid,
                gemcount: 15
              })
              // FIXME: error below
              .then(() => {
                db.collection("users").doc(this.slug).get().then((doc) => {

                    let data = doc.data()
                    db.collection("users").doc(cred.user.uid).set(data).then({
                      db.collection("users").doc(this.slug).delete()
                    })

                })
              })
              .then(() => {
                this.$router.push({ name: 'Core' })
              })
            })
            .catch(err => {
              console.log(err)
              this.feedback = err.message;
            })
          }
        })
      } else {
        this.feedback = 'Please enter a heroName'
      }
    }
  }

【问题讨论】:

    标签: firebase firebase-realtime-database vue.js vuejs2 firebase-authentication


    【解决方案1】:
    db.collection("users").doc(cred.user.uid).set(data).then({
         db.collection("users").doc(this.slug).delete()
    })
    

    then期望它的参数是一个函数,我估计你的错误来自哪里,正确的应该是:

    db.collection("users").doc(cred.user.uid).set(data).then(() => {
         db.collection("users").doc(this.slug).delete()
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      • 2019-01-19
      • 1970-01-01
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多