在非微信里面使用web-component定义wx-open-launch-weapp方便调试样式
发布于 4 年前 作者 omao 1913 次浏览 来自 分享
(function(){
    var userAgent = navigator.userAgent && navigator.userAgent.toLowerCase() || '';
    if (userAgent.match(/MicroMessenger/i) != "micromessenger") {
        class WxOpenLaunchWeapp extends HTMLElement
        {
            constructor()
            {
                super();
                this.shadow = this.attachShadow({ mode'open' });
            }
            connectedCallback() {
                var template = this.querySelector("script,template");
                if (template) {
                    this.shadow.innerHTML = template.innerHTML;
                    this.removeChild(template);
                }
            }
        }
        window.customElements.define('wx-open-launch-weapp', WxOpenLaunchWeapp);
    }

})();

1 回复

第一次用web-component,这只是其中一种定义web-component的方式,如有问题请见谅

回到顶部