关于方法调用微信小程序API 等待的问题
自定义的方法时需要判断本地是否有文件所以需要调用getFileInfo方法,然后进行文件处理[代码]function[代码] [代码]getLocalIcon(name) {[代码][代码] [代码][代码]let iconPath = [代码][代码]"../images/category_ico/"[代码][代码];[代码][代码] [代码][代码]let tail = [代码][代码]".png"[代码][代码];[代码][代码] [代码][代码]var[代码] [代码]link = iconPath + name + tail;[代码][代码] [代码][代码]var[代码] [代码]ret = [代码][代码]''[代码][代码];[代码][代码] [代码][代码]wx.getFileInfo({[代码][代码] [代码][代码]filePath: link,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](data) {[代码][代码] [代码][代码]ret = link;[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](data) {[代码][代码] [代码][代码]ret = hosts + [代码][代码]'icon/'[代码] [代码]+ name + tail;[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete: [代码][代码]function[代码][代码](){[代码][代码] [代码][代码]console.log(ret); //打印一[代码][代码] [代码][代码]return[代码] [代码]ret;[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]return[代码] [代码]ret;[代码][代码]}[代码]在调用方法时出现wx.getFileInfo方法被执行前就已经返回结果的问题 [代码]icon = parseInt(bean.icon) == 0 ? wxLink.getLocalIcon(bean.img_url) : wxLink.getImgLink(bean.img_url,[代码][代码]'icon'[代码][代码]);[代码] console.log(icon) //打印二 打印顺序为 打印二 打印一 并且打印二一的结果是对的,打印二的结果为''