Polymer 1.x默认使用Shady DOM,但可以在初始化时通过在导入polymer.html之前设置window.Polymer对象来更改,如下所示:
<script>window.Polymer = {dom: 'shadow'};</script> <link rel="import" href="polymer.html">
然而,似乎Polymer 2.0使用Shadow DOM而不管window.Polymer = {dom:’shady’}.如何切换到Shady DOM?
解决方法
Shady DOM垫片是
factored out of Polymer in 2.0并移动到v1 Web Components polyfill中.
要启用Shady DOM(而不是默认的Shadow DOM),请在导入v1 webcomponents-lite.js之前定义以下window.ShadyDOM对象:
<script>window.ShadyDOM = { force: true };</script> <script src="webcomponentsjs/webcomponents-lite.js"></script>
更新:更简单的设置是在< script>上指定[shadydom]标签:
<script src="webcomponentsjs/webcomponents-lite.js" shadydom></script>