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

181
Vistas
VueJS this.progress is undefined inside window function

I'm using a Facebook login and I'm showing progress loading for the user until I get a response back from Facebook for authentication. But I used to hide the progress bar like this.progress = false but this variable is undefined inside the window function.

My code :

initFacebook() {
    this.progress=true
      window.fbAsyncInit = function() {
        window.FB.init({
          appId: "MY-APP-ID", //You will need to change this
          cookie: true, // This is important, it's not enabled by default
          version: "v2.6",
          status: false,
        });
        
        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 ;)
    })
     
        } else {
          console.log("User cancelled login or did not fully authorize.")         

        }

      },
      
      {scope: 'public_profile,email'}
      );
    this.progress = false
console.warn(this.progress)

      };

    },

I'm unable to set this.progress = false after getting all responses from Facebook.

I get an error while I console.log(this.progress) variable.

Error :

Login.vue?7463:175 undefined

How can I set this.progress variable to false once the authentication checks are complete?

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

0

Try converting all function() calls into arrow function calls () =>

The problem is that a function() will break the global vue scope. So vue this is not available within a function() call, but it is available within an arrow function () => {}

In a block scope (function() { syntax), this is bound to the nested scope and not vue's this instance. If you want to keep vues this inside of a function, use an arrow function (ES6) or you can have const that = this and defer the global this to that in a regular function() { if you prefer it this way.

Try using this code converted with arrow functions and see if it works:

initFacebook() {
  this.progress=true
    window.fbAsyncInit = () => {      
      window.FB.init({
        appId: "MY-APP-ID", //You will need to change this
        cookie: true, // This is important, it's not enabled by default
        version: "v2.6",
        status: false,
      });

      window.FB.login((response) => {            
        if (response.status === 'connected'){
          window.FB.api('/me?fields=id,name,email', (response) => {
            console.log( response) // it will not be null ;)
          })     
        } else {
          console.log("User cancelled login or did not fully authorize.")
        }
      },      
    {scope: 'public_profile,email'});
    this.progress = false
    console.warn(this.progress)
  };
},

I know this because I just had the same problem :-) see here: Nuxt plugin cannot access Vue's 'this' instance in function blocks

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