我需要你的帮助。我试图调用它来访问我在vuejs中的数据对象中的变量,但是这个返回未定义
这是我的代码
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
}
})
任何人都可以帮我解决它是怎么做的吗?谢谢和问候。
答案 0 :(得分:2)
您定义
let self = this
顶部,
但在function(data, self)
内部会被覆盖。更改其中一个变量并使用它而不是这个。
或者将this
绑定到函数,以便在以下内容中使用它:
function(data, self) {
}.bind(this)