【发布时间】:2018-01-29 10:00:33
【问题描述】:
在我的自定义元素的connectedCallback() 方法中,textContent 作为空字符串返回。
基本上我的代码归结为以下...
class MyComponent extends HTMLElement{
constructor() {
super()
console.log(this.textContent) // not available here, but understandable
}
connectedCallback() {
super.connectedCallback() // makes no difference if present or not
console.log(this.textContent) // not available here either, but why?!
}
}
customElements.define('my-component', MyComponent);
还有 HTML...
<my-component>This is the content I need to access</my-component>
从阅读有关connectedCallback() 的内容来看,它听起来好像是在将元素添加到 DOM 后调用的,所以我希望 textContent 属性应该是有效的。
如果有帮助,我正在使用 Chrome 63...
【问题讨论】:
标签: javascript web-component custom-element native-web-component