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



我一直在按照指南学习自定义元素。我可以让基本的工作

.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/

可能出了什么问题?

应该提到我正在使用电子

好的,在电子中的铬更新到 67 之前,它不起作用。

最新更新