// 动态加载script的方法
function loadImage(src) {
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
    fail = _ref.fail,
    success = _ref.success;
  return new Promise(function (resolve) {
    var img = new Image();
    img.src = src;
    var handleLoad = function handleLoad() {
      resolve(true);
      if (typeof success === 'function') success(img);
      img.removeEventListener('load', handleLoad);
      img.removeEventListener('error', handleError);
    };
    var handleError = function handleError() {
      resolve(false);
      if (typeof fail === 'function') fail();
      img.removeEventListener('load', handleLoad);
      img.removeEventListener('error', handleError);
    };
    img.addEventListener('load', handleLoad);
    img.addEventListener('error', handleError);
  });
}
export default loadImage;