自定义的内置元素在Electron中不起作用

时间:2018-06-30 17:25:20

标签: javascript html electron

following the guides一直在学习有关自定义元素的知识。我可以得到基本的工作

JS

class MyText extends HTMLElement {
    constructor(){
        super();
        console.log('test')
    }
}
customElements.define('my-text', MyText);

HTML

<my-text>Hi?</my-text>

控制台输出

  

测试

但是我无法使继承的格式起作用。它似乎没有调用构造函数。

JS

class StatusText extends HTMLSpanElement {
    static get observedAttributes() {return ['status']; }

    constructor(){
        super();
        console.log("hello??");
        return this;
    }

    attributeChangedCallback(name, oldValue, newValue) {
        console.log('Custom element attributes changed.');
        console.log(name, oldValue, newValue);
    }
}
customElements.define('status-text', StatusText, {extends: "span"});

HTML

<span is="status-text" status="ok">Hi?</span>

控制台输出

(什么都没有)

最糟糕的是,我什至尝试将可以在Chrome上运行的示例复制粘贴到我自己的代码中,以某种方式,它不适用于Electron。

https://mdn.github.io/web-components-examples/expanding-list-web-component/

怎么了?

我应该提到我正在使用电子

1 个答案:

答案 0 :(得分:0)

好吧,直到电子中的铬更新为67才起作用。