聚合物1.0中使用了content元素吗? [英] Is the content element used in Polymer 1.0?
问题描述
https://www.polymer-project. org/1.0/docs/devguide/local-dom#dom-distribution
在上面的"Dom分发"下的链接中说:
In the above link under "Dom Distribution" it says:
为了支持元素的轻型DOM与本地DOM的组合,Polymer支持
<content>
元素. ...
To support composition of an element's light DOM with its local DOM, Polymer supports the
<content>
element. ...
只是想知道这是否过时了?聚合物1.0是否按此处所述使用插槽?
Just wondering if this is out of date? Does Polymer 1.0 use slots as described here?
https://developers.google.com/web /fundamentals/primers/shadowdom/?hl = zh-CN#composition_slot
推荐答案
即使使用Shadow DOM,它也可以在Polymer 1.0中正常工作.我目前在使用Polymer 1.6的项目中使用它,但是它在Polymer 2.0或更高版本中可能已过时.
It's definitely working in Polymer 1.0, even with Shadow DOM; I'm currently using it in my projects which use Polymer 1.6, but it may be outdated in Polymer 2.0 or a newer version.
@ebidel确认他们会将插槽添加到webcomponents.js,但目前没有人分配给它:
@ebidel confirmed that they will add the slots to webcomponents.js, but currently nobody is assigned to it: https://github.com/webcomponents/webcomponentsjs/issues/430
更新
在Polymer 1.7中,他们引入了准备升级到2.0的<slot>
元素,应该很快发布. 2.0将没有<content>
元素,因为它们切换到CustomElement v1规范.我建议,如果您打算使用<content>
元素,然后将其切换到插槽,那么将来您就可以升级聚合物库而无需进行大量迁移.
In the Polymer 1.7 they introduced the <slot>
element for preparing to upgrade to 2.0 wich should be released soon. The 2.0 will not have the <content>
element because they switching to the CustomElement v1 spec. I recommend that if you are plan to use <content>
element then switch it to slot so in the future you will able to just upgrade the polymer library without heavy migrating.
插槽的工作方式略有不同,该插槽没有选择器:
The slot is working a bit different, the slot does not have a selector:
<dom-module id="my-element">
<template>
<slot name="content"></slot>
</template>
<script>
Polymer({
is: 'my-element'
});
</script>
</dom-module>
<my-element>
<div slot="content">My Content</div>
</my-element>
这篇关于聚合物1.0中使用了content元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!