私はshadow domに問題があります。 I ve found a tutorial that seems a bit old about shadow dom and it
は、createshadowrootを使用しています。私はcreatedhadowrootが推奨されておらず、attachshadowに置き換えなければならないという通知を受けました。なぜ、createshadowrootが私に別の結果を与えてからattachshadowを与えるのですか?
問題i m having is that attachshadow does not produce the desired effect while using templates. It
は、自分の要素の内容をhtmlにコピーしません。 attachShadow
結果に
var nameTags = document.querySelectorAll('.nameTag');
for (i = 0; i < nameTags.length; ++i)
{
//var shadow = nameTags[i].attachShadow({ mode: 'open' });
var shadow = nameTags[i].createShadowRoot();
var template = document.querySelector('#nameTagTemplate');
var clone = document.importNode(template.content, true);
console.log(shadow);
console.log(template);
console.log(template.content);
console.log(clone);
shadow.appendChild(clone);
}
結果:ここで
は、私が使用しているコードです。コンテンツはattachShadowで正しくコピーされていませんが、それでもs createShadowRoot that is deprecated. I don
は、将来的にサポートが提供されるため、すべてをcreateShadowRootでコーディングしたいと考えています。何が起こっている?シャドウDOM v1のattachShadow()
で