【发布时间】:2017-11-22 08:35:25
【问题描述】:
在 Polymer 2.0 中实现内部链接(在同一页面内链接)的正确方法是什么?我似乎无法访问隐藏在 ShadowDoms 中的组件,因此使用 <a href="#my_section">link to top</a> 和 <a name="my_section"></a> 和 <a id="my_section"></a> 的传统方式不起作用。
我也尝试了这里的解决方案,但无济于事:
- How to query elements within shadow DOM from outside in Dart?
- Is it possible to access Shadow DOM elements through the parent document?
- Using querySelector to find nested elements inside a Polymer template returns null
我尝试过的以下代码都返回 null,即使我向组件添加了 id:
document.querySelector('#my_section'); //null
this.$.my_section; //null
this.root.querySelector('#my_section'); //null
this.shadowRoot.querySelector('#my_section'); //null
也许有一种方法可以使用<app-route> 完成此操作?
我对 Polymer 很陌生,因此我们将不胜感激。提前致谢。
【问题讨论】:
-
"#my_section" 查询
<a id="my_section">?你确定要使用名字吗? -
@daKmoR 我实际上也尝试过“id”,但这也不起作用。我已经更新了问题。
-
您是从元素内部还是外部进行查询?
-
嗨@codeMonkey,我正在从元素外部查询。
标签: polymer shadow-dom polymer-2.x