我正在尝试使用Polymer ShadowDOM和Custom Elements
的{{3}}填充物如果我单独使用它们,它们运行良好,但当我同时使用它们时,我会收到这样的错误
Uncaught TypeError: Cannot read property 'polymerShadowRoot_' of undefined.....Element.js:69
这取决于我是否首先包含customelement.js或shadowdom.js
这是我的测试代码:
<!doctype html>
<html>
<head>
<script src="/bower_components/CustomElements/custom-elements.js"></script>
<script src="/bower_components/ShadowDOM/shadowdom.js"></script>
<script>
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() {
console.log('create shadowDOM');
var root = this.createShadowRoot();
root.innerHTML = '<content></content>';
};
document.register('x-foo', {prototype: proto});
</script>
</head>
<body>
<x-foo><span>hallo</span></x-foo>
</body>
</html>
有什么建议可能会出错吗?
答案 0 :(得分:1)
每当使用ShadowDOM polyfill时,必须首先加载它,因为它完全重新映射DOM。其他库(通常)可以在重映射之上加载,但不能在下面加载。