0

I included some external SDK into my component:

mounted() {
    // Load external Script
    let externalScript = document.createElement('script')
    externalScript.setAttribute('src', 'https://x.klarnacdn.net/kp/lib/v1/api.js')
    document.head.appendChild(externalScript)
    ...

Later I am receiving a callback like this:

authorizeKlarna: function(){  
        Klarna.Payments.authorize({
        payment_method_category: "pay_later"
        }, function(res) {
        console.debug(res);
        if(res.approved == true){ 
            this.token = res.authorization_token
        }
        })
      },

However this.token will not be updated because I am out of scope. Is there any simple way how to access data of my vue component from this external callback?

1 Answer 1

1

Try changing your function(res) to Arrow Function (res) =>

authorizeKlarna: function(){  
  Klarna.Payments.authorize(
  { payment_method_category: "pay_later" },
  (res) => {
    console.debug(res);
    if(res.approved == true){ 
      this.token = res.authorization_token
    }
  }
)
},
Sign up to request clarification or add additional context in comments.

1 Comment

That's it. Thank you so much!

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.