0

please i need your help. I am trying to call this to access a variable that i have in my data object in vuejs but this returns undefined

Here is my code

let response = ''
        let self  = this

        response = WePay.credit_card.create({
          "client_id":        118711,
          "user_name":        this.cardDetails.name,
          "email":            this.cardDetails.email,
          "cc_number":        this.cardDetails.number,
          "cvv":              this.cardDetails.cvc,
          "expiration_month": this.cardDetails.month,
          "expiration_year":  this.cardDetails.year,
          "address": {
              "postal_code": this.cardDetails.zipcode
          }
        }, function(data, self) {
          if (data.error) {
            // self.loader = false
            console.log(window)
            this.loader = false
            this.emitErrorNotify({message: data.error_description})
            // handle error response
          } else {
            console.log(data)
              // call your own app's API to save the token inside the data;
              // show a success page
          }
        })

Please can anyone help me how it's done? Thanks and regards.

Mbengchan
  • 166
  • 3
  • 17

1 Answers1

2

You define

let self  = this

up top, but inside the function(data, self) self is overwritten. Either change one of the variables and use that instead of this. Or bind this to the function so you can use it within:

function(data, self) {

}.bind(this)