答案 0 :(得分:0)
这是一个范围问题,用这样的箭头函数替换函数回调:
apiServer.getBalance(myData.token, myData.id, response => {
if (response.success) {
console.log("Balance success");
balance = response.success.balance;
this.setState({ balance: response.success.balance });
} else {
//login failed
console.log("failed");
}
});
快乐的编码。