Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
VueJS button click executes only second click

I have "Sign in with facebook" button in my webpage. everything working as expected but the problem is the action is triggered in second time of click. i cans ee error in console in first click.

HTML Code :

 <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                    <button type="button"  v-on:click="logInWithFacebook" class="btn-facebook"><i class="fa fa-facebook"></i>Facebook</button>
                </div>

JS code :

<script>

import axios from 'axios'

export default {

    name:"Login",
    data() {

        return {

            email:'',
            password:'',
            progress:false,
            disabled:false,
            emailError:null,
            passwordError:null,
            error:null,
            

        }

    },

    methods: {

async initFacebook() {
      window.fbAsyncInit = function() {
        window.FB.init({
          appId: "615100826501510", //You will need to change this
          cookie: true, // This is important, it's not enabled by default
          version: "v2.6"
        });
      };
    },
      async logInWithFacebook() {
      this.progress=true
      await this.loadFacebookSDK(document, "script", "facebook-jssdk");
      await this.initFacebook();
      window.FB.login(function(response) {
           if (response.status === 'connected'){

        window.FB.api('/me?fields=id,name,email', function(response) {
        console.log( response) // it will not be null ;)
        this.progress = false

    })
          
        } else {
          alert("User cancelled login or did not fully authorize.");
        }
      },
      {scope: 'public_profile,email'}
      );
      return false;
    },
    async loadFacebookSDK(d, s, id) {
      var js,
        fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {
        return;
      }
      js = d.createElement(s);
      js.id = id;
      js.src = "https://connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
    }

    }
      


Console error :

vue.runtime.esm.js?2b0e:1897 TypeError: Cannot read properties of undefined (reading 'login')

I'm getting this console error in the first click and the second time it works fine. I Think the error happens this line in first click.

window.FB.login(function(response) {

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think it's because on the first click,window.FB.login will be executed faster than this.initFacebook

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda