时间:2019-05-03 来源:小程序工厂
匿名函数是个好东西
感谢各位的帮助,通过你们的回复我受到启发,现在改用指针的方式实现循环了。谢谢各位。
myscanCode: function() {
wx.scanCode({
success: (res) => {
var count = this.data.scanCount;
this.setData({
scanCount: count + 1,
});
if (this.data.scanCount <= this.data.scanCountMax)
this.myscanCode();//重复执行
},
fail: (res) => {},
})
},
封装成函数,传参在for循环里面调用了for(let i = 0; i < 5; i += 1){myScanCode(i);}这个方法简单
test: function() {
const num = 5
let count = 0
for (var i = 0; i < num; i++) {
wx.scanCode({
onlyFromCamera: true,
scanType: [],
success: function(res) {},
fail: function(res) {},
complete: function(res) {
count++
if (count == num) {
console.log(我执行完了)
}
},
})
}
}
封装成函数,传参在for循环里面调用了for(let i = 0; i < 5; i += 1){myScanCode(i);}
for (var i = 0; i < 5; i++) { (function (i) { wx.scanCode({ success: (res) => { wx.showToast({ title: '成功' + i, icon: 'success', duration: 2000 }) } }) })(i)}