UNPKG

m2-webui

Version:

The package is provided web components and utilities based on vue and element-ui.

36 lines (33 loc) 712 B
'use strict'; exports.__esModule = true; var imageIsExist = function imageIsExist(url) { return new Promise(function (resolve) { var img = new Image(); img.onload = function () { if (this.complete === true) { resolve(true); img = null; } }; img.onerror = function () { resolve(false); img = null; }; img.src = url; }); }; var setImg = function setImg(el, binding) { var imgURL = binding; if (imgURL) { imageIsExist(imgURL).then(function (res) { if (res && el) { el.setAttribute('src', imgURL); } }); } }; exports.default = { inserted: function inserted(el, binding) { setImg(el, binding.value); } };