uni.requset的data怎么作为值返回到函数

weixin_43800906 2019-04-14 02:54:00
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的值然后返回到函数。这样应该是错的。百度说要异步。但是我不会,有大神帮忙改一下吗
...全文
238 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_43800906 2019-04-14
  • 打赏
  • 举报
回复
引用 4 楼 囧的回复:
button上设置 v-if="showFollow" 在mounted里调用this.isFollowed(followed.fromUId) if(res.data.data!=null){ _this.showFollow = false; }else{ _this.showFollow = true; }
还是不懂,我的fromUId是循环的,不过谢谢大神了。这个功能我就不写了。太麻烦了
2019-04-14
  • 打赏
  • 举报
回复
button上设置 v-if="showFollow" 在mounted里调用this.isFollowed(followed.fromUId) if(res.data.data!=null){ _this.showFollow = false; }else{ _this.showFollow = true; }
weixin_43800906 2019-04-14
  • 打赏
  • 举报
回复
引用 1 楼 囧的回复:
用回调函数来处理返回结果

ifFollowed:function(callback){
	...
	if(res.data.data!=null){
		callback(false);
	}else{
		callback(true);
	}
}

obj.ifFollowed(function(result)){
	console.log(result);
	//后续操作
});
大佬,我不会调用。能不能再帮我下,代码在下方
weixin_43800906 2019-04-14
  • 打赏
  • 举报
回复
<button v-if="ifFollowed(followed.fromUId)" class="followed-btn">关注</button>
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是否显示。昨晚太晚了。忘记发全了
2019-04-14
  • 打赏
  • 举报
回复
用回调函数来处理返回结果

ifFollowed:function(callback){
	...
	if(res.data.data!=null){
		callback(false);
	}else{
		callback(true);
	}
}

obj.ifFollowed(function(result)){
	console.log(result);
	//后续操作
});
//微信充 //支付接口测试 function balance(url, data) { uni.request({ url: cfg.originUrl + '/wx/mp/js_sig.do', data: { route: url }, method: 'GET', success: (res) => { jweixin.config({ debug: true, // 开启调试模式,调用的所有api的返回会在客户端alert出来 appId: res.data.appId, // 必填,公众号的唯一标识 timestamp: res.data.timestamp, // 必填,生成签名的时间戳 nonceStr: res.data.nonceStr, // 必填,生成签名的随机串 signature: res.data.signature, // 必填,签名 jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表 }); jweixin.ready(function() { uni.request({ url: cfg.originUrl + '/wx/recharge/pay.do', method: 'POST', header: { 'Content-type': "application/x-www-form-urlencoded", }, data: JSON.stringify(data), success: function(res) { alert("下单成功"); alert(JSON.stringify(res)); alert(res.data.order_id); all.globalData.orderId = res.data.order_id; uni.setStorageSync('orderId', res.data.order_id); jweixin.chooseWXPay({ timestamp: res.data.payParams.timeStamp, // 支付签名时间戳 nonceStr: res.data.payParams.nonceStr, // 支付签名随机串 package: res.data.payParams.package, // 接口返回的prepay_id参数 signType: res.data.payParams.signType, // 签名方式 paySign: res.data.payParams.paySign, // 支付签名 success: function(e) { alert("支付成功"); alert(JSON.stringify(e)); // 支付成功后的回调函数 } }); } }) }); jweixin.error(function(res) { // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。 console.log("验证失败!") }); } }) }

87,909

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧