使用 customElement 裝飾器建立自定義元素

在大多數示例中,類命名約定用於定義 Aurelia 自定義元素。但是,Aurelia 還提供了一個可用於裝飾類的裝飾器。然後,Aurelia 再次將該類視為自定義元素。

提供給裝飾器的值將成為自定義 HTML 元素的名稱。

示例: my-element.js

import {customElement} from 'aurelia-framework';

@customElement('robots')
export class MyClass {

}
<template>
    <h1>I am a robots custom element</h1>
</template>

使用它:

<template>
    <require from="./my-element"></require>

    <robots></robots>
</template>