1 回答

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
它不工作,因?yàn)槟愦螂娫抍ustomElements.define-and從而升級(jí)<neo-element>到的實(shí)例NeoElement,之前你已經(jīng)定義NeoElement.prototype,NeoElement.prototype.constructor和NeoElement.prototype.connectedCallback。
如果你移動(dòng)customElements.define到最后它工作正常:
function NeoElement() {
var ref = Reflect.construct(HTMLElement,[], this.constructor) ;
return ref;
};
NeoElement.prototype = Object.create(HTMLElement.prototype);
NeoElement.prototype.constructor = NeoElement;
NeoElement.prototype.connectedCallback = function(){
this.innerHTML = `<h1>Hello world</h1>`;
};
customElements.define('neo-element', NeoElement);
<neo-element></neo-element>
添加回答
舉報(bào)