VueJS - variable is defined but never used (Sending Data to Firebase)

Viewed 1044

I have an issue when learning VueJS. I want to send data to Firebase, but it keeps telling me that the variables never used. I declare it inside a promise.

This is the script:

methods: {
        register: function() {
          const info = {
            email: this.email,
            password: this.passOne,
            displayName: this.displayName
          };

          if(!this.error) {
              Firebase.auth()
              .createUserWithEmailAndPassword(info.email, info.password)
              .then( 
                userCredentials => {
                  this.$router.replace('meetings');
                },
                error => {
                  this.error = error.message;
                }
              );
          }
        }
    },

This is the error:

error    'userCredentials' is defined but never used  no-unused-vars
2 Answers

Thats an es-lint error. To solve:

            if(!this.error) {
              Firebase.auth()
               .createUserWithEmailAndPassword(info.email, info.password)
              .then( 
                 () => {
                    this.$router.replace('meetings');
               },

or you can also ask es-lint to do not look for the next line:

           //es-lint-disable-next-line no-unused-vars
           .then( userCredentials => {
              this.$router.replace('meetings');
            },

replace your $router.replace(...) code like below

this.$router.replace({ name: 'meetings', params: { credentials: userCredentials } })

hope it will solve your issue.

Related