Aurelia:从另一个派生组件并重用 HTML

Aurelia: Deriving a component from another and reusing HTML

在 Aurelia 中,如何重用源组件的 HTML 视图从另一个组件派生组件?

我有一个组件 BarGraph 可以呈现简单的条形图。该组件有文件 bar-graph.jsbar-graph.html。我想从 BarGraph 中导出一组组件。每个 *BarGraph class 都将具有自定义逻辑,但所有派生组件都将具有与原始组件相同的 HTML。我想将组件的 HTML 存储在一个文件中,并在每个 *BarGraph class 中重复使用它。

您可以使用 @useView。例如:

import {useView} from 'aurelia-framework';

@useView('./bar-graph.html')
export class AnotherBarGraph {
  // Your logic here
}

文档here

编辑:目前不支持使用继承扩展自定义元素。重要的一点是"Inheritance of Bindables doesn't work"。看到这个 issue.