vue-plugin-load-script icon indicating copy to clipboard operation
vue-plugin-load-script copied to clipboard

[Feature Request] Add style support

Open mahammad-sixberries opened this issue 4 years ago • 0 comments

function loadStyle (href) { 
  return new Promise(function (resolve, reject) {
    let shouldAppend = false;
    let el = document.querySelector('link[href="' + href + '"]');
    if (!el) {
      el = document.createElement('link');
      el.rel = 'stylesheet';
      el.async = true;
      el.href = href;
      shouldAppend = true;
    }
    else if (el.hasAttribute('data-loaded')) {
      resolve(el);
      return;
    }

    el.addEventListener('error', reject);
    el.addEventListener('abort', reject);
    el.addEventListener('load', function loadScriptHandler() {
      el.setAttribute('data-loaded', true);
      resolve(el);
    });

    if (shouldAppend) document.head.appendChild(el);
  });
};

mahammad-sixberries avatar Apr 26 '21 07:04 mahammad-sixberries