微信小程序使用Promise异步回调,以及使用简单递归算法
个人分类://分享好友
onShareAppMessage: function () {
var that = this;
return new Promise((resolve,reject)=>{
wx.showLoading({
title: '正在生成中...',
icon: 'none'
})
var index = 0; //计数循环
var recursiveFunc = function () {
if (isEmty(that.data.shareItemImageUrl) && index < 10) {
setTimeout(() => {
index++; //计数+1
recursiveFunc(); //再次执行
}, 500);
} else {
//递归结束退出递归
wx.hideLoading();
resolve({
title: that.data.shareTitle,
path: 'pages/index/home?id=' + that.data.shareId,
imageUrl:that.data.shareItemImageUrl
})
}
}
recursiveFunc(); //执行
})
},
如有任何知识产权、版权问题或理论错误,还请指正。转载请附上原文出处链接。