【问题标题】:Aurelia Custom Elements & ContentAurelia 自定义元素和内容
【发布时间】:2016-01-12 22:01:57
【问题描述】:

我正在阅读this tutorial,我想做类似的事情,但我不想使用我的自定义元素的属性,而是想访问我的自定义元素标签内的内容。我似乎无法弄清楚这一点。所以不是像这样的html:

<modal>  
  <modal-header title="Edit Person"></modal-header>
  <modal-body content="person-information"></modal-body>
  <modal-footer buttons.bind="['Cancel']"></modal-footer>
</modal>  

我希望它看起来更像这样:

<modal>  
  <modal-header>Edit Person</modal-header>
  <modal-body>
      <form>...</form>
  </modal-body>
  <modal-footer buttons.bind="['Cancel']"></modal-footer>
</modal>  

这可能吗?

【问题讨论】:

    标签: aurelia


    【解决方案1】:

    是的,可以使用内容选择器来完成 -

    modal-header.html

    <template>
      <slot></slot>
    </template>
    

    您也可以通过使用任何标准 CSS 选择器指定要匹配的内容来更具体 -

    <template>
      <slot="form"></slot>
      <slot select=".form-element"></slot>
    </template>
    

    Aurelia documentation

    【讨论】:

    • 我不确定我做错了什么,但&lt;custom-element&gt;Here's my content&lt;/custom-element&gt;&lt;template&gt;&lt;div class="my-custom-element"&gt;&lt;content&gt;&lt;/content&gt;&lt;/div&gt;&lt;/template&gt; 最终得到了一个空的 div:/
    • 请注意,根据 Shadow DOM 规范的最新更改,Aurelia 版本 1 中的 &lt;content&gt; 标签已替换为 &lt;slot&gt; 标签。 Aurelia documenation
    • 一定要编辑欢迎,否则我会尽量做到这一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 2019-05-24
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多