ifFollowed:function() {
var _this = this;
uni.request({
url: this.apiServer + '/follow/one',
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: {
fromUId: uni.getStorageSync('login_key').userId,
toUId: 7
},
success: (res) => {
if(res.data.data!=null){
return false;
}else{
return true;
}
}
});
},如代码所示。我想判断data的值然后返回到函数。这样应该是错的。百度说要异步。但是我不会,有大神帮忙改一下吗
var _this = this;
uni.request({
url: this.apiServer + '/follow/one',
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: {
fromUId: uni.getStorageSync('login_key').userId,
toUId: 7
},
success: (res) => {
if(res.data.data!=null){
return false;
}else{
return true;
}
}
});
},如代码所示。我想判断data的值然后返回到函数。这样应该是错的。百度说要异步。但是我不会,有大神帮忙改一下吗
...
if(res.data.data!=null){
callback(false);
}else{
callback(true);
}
}obj.ifFollowed(function(result)){
console.log(result);
//后续操作
});
ifFollowed:function(aId) {
var _this = this;
uni.request({
url: this.apiServer + '/follow/one',
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: {
fromUId: uni.getStorageSync('login_key').userId,
toUId: aId
},
success: (res) => {
if(res.data.data!=null){
return false;
}else{
return true;
}
}
});
},
完整是这样的,请问我改如何在上面调用啊。我想用这个值判断button是否显示。昨晚太晚了。忘记发全了
button上设置 v-if="showFollow"在mounted里调用this.isFollowed(followed.fromUId)if(res.data.data!=null){
_this.showFollow = false;
}else{
_this.showFollow = true;
}