【发布时间】:2018-04-26 13:56:10
【问题描述】:
使用聚合物,我在通过标签名称选择元素时遇到问题。
<canvas id="chart" width="150" height="150"></canvas>
.
..
...
_drawChart(price, time) { var ctx = this.$.canvas.getContext('2d'); //error happened here
.
..
...
}
现在this.$.canvas.getContext('2d'); 在控制台中返回错误Uncaught TypeError: Cannot read property 'canvas' of undefined.
我通过 getElementById 从控制台手动选择元素,它返回 null,注意画布位于 shadow-root 树中。
【问题讨论】:
标签: polymer web-component shadow-dom