onLoad(e){
setTimeout(() => {
let that = this;
uniCloud.callFunction({name: 'api',data: {action:e.ac,},
success: (e) => {
if (e.result.code == 0) {
var n = 1;
if(n === 0){
//this.detail = e.result.data.data['0']; // 这里用this不行。
console.log(e.result.data.data['0']);
//console.log(this.detail);
}else if(n === 1){
//that.detail = e.result.data.data['0']; // 这里用that也不行。
console.log(e.result.data.data['0']);
}else if(n === 2){
setTimeout(function(){
this.detail = e.result.data.data['0']; //只有这里是对的
console.log(this.detail);
},1);
}else{
setTimeout(function(){
console.log(e.result.data.data['0']);
that.detail = e.result.data.data['0'];//setTimeout里面用that也不对
},1);
}
} else {
uni.showModal({
content: e.result.message,
showCancel: false
})
}
},
fail: (e) => {
uni.showModal({
content: JSON.stringify(e),
showCancel: false
})
},
complete: () => {
}
})
}, 0) //箭头函数中的this总是指向外层调用者,也就是Obj
},