When a custom method invokes a component in Javascript, you need to wait before the result is returned.

when customizing the method, you need to determine whether there is a file locally, so you need to call the getFileInfo method, and then process the file

.
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;
}

call method

icon = parseInt(bean.icon) == 0 ? wxLink.getLocalIcon(bean.img_url) : wxLink.getImgLink(bean.img_url,"icon");

console.log(icon)   //

print order is print two print one.
executes the wx.getFielInfo method when the method getLocalIcon is called, but when executing the wx.getFielInfo result, it returns the great gods of ret, who want to consult the forum. How to set the wait to let the result pause return first when calling wx.getFieldInfo?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e464f0-440e8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e464f0-440e8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?