1
私はskate.jsを使用しており、検証と操作のためにWebコンポーネントのLight DOMを参照しようとしています。私はそれがあることを検証し、シャドウDOMラベルがfor
属性でそれを参照する使用することができますので、それにIDを追加するためのチェックボックスを参照しようとしているWebコンポーネント内でLight DOMを参照する
<res-checkbox>
<label slot="label">This is res-checkbox</label>
<input slot="checkbox" type="checkbox" id="test-id" />
</res-checkbox>
:コンポーネントは次のようになります。しかし、コンポーネントがレンダリングされた後に、その参照方法を理解することはできません。
import { Component, h, define, prop } from 'skatejs';
export class ResComponent extends Component {
static get is() { return 'res-checkbox'; }
renderedCallback() {
console.log(this.querySelector('input[type="checkbox]'));
// -> null
console.log(this.getElementsByTagName('input')[0]);
// -> undefined
console.log(this.shadowRoot.querySelector('input[type="checkbox]'));
// -> null
console.log(this.shadowRoot.getElementById('checkbox').querySelector('input'));
// -> null
console.log(this.shadowRoot.getElementById('checkbox').assignedNodes());
// -> []
console.log(this.childNodes[1]);
// -> undefined
console.log(this.children[1]);
// -> undefined
}
renderCallback() {
return <div id="wrap">
<slot name="label" id="label"></slot>
<label id="fakeCheckbox">
<slot name="checkbox" id="checkbox"></slot>
</label>
</div>;
}
}
define(ResComponent);
ウェブコンポーネントで軽いDOMを参照するにはどうすればよいですか?
うんで実行されている例です。それは間違いなく機能します。私はskate.jsレポに関する問題を開いて、私がそれらからいくつかの指導を得ることができるかどうかを見ていきます。ありがとう! – bjork24