0

I try to using JavaScript SDK in Vuejs, I use login facebook button:

<template>
  <div>
  <div class="fb-login-button" data-max-rows="1" data-size="large" data-button-type="login_with" data-show-faces="false" data-auto-logout-link="true" data-use-continue-as="false" onlogin="checkLoginState();">
  </div>
 </div>
</template>
<script>
  export default {
   data() {
     return: { }
   },
   methods: {
    checkLoginState: function() {
      console.log("logged")
     }
   }
  }
</script>

However, I cannot see result. How can I fix this error?

2
  • Please show all of your Vue code. Where is your Vue instance, Vue component etc? Commented Mar 14, 2018 at 8:09
  • I just write one component, have a login with facebook button. I only want to try to show something after login success. I login success to facebook, but it cannot show something in console.log Commented Mar 14, 2018 at 8:17

1 Answer 1

1

This is because the Facebook SDK only knows about the function in the window scope, your function is in the local scope. This is true for so many, many other libraries. The solution is to bind this to the window when you create / mount the component.

created() {
    window.checkLoginState = this.checkLoginState
}

Now your local component method will be called when the onlogin event is returned from the FB api.

Alternatively you can use other binding syntaxes, or just build the button yourself.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I didn't know window and local scope =))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.