4

In Aurelia, when does the exported view-model class name matter? Html and JS files are linked by the name but the name of the class inside doesn't seem to matter.

By default, loader seems to grab first exported class as the view-model no matter the name of the class. It does to recognize 'ValueConverter' suffix but other than that first class exported wins.

Is this by convention?

4

1 回答 1

11

命名对于视图模型来说根本不重要。但是,视图模型应该是不使用约定或不提供元数据的模块的唯一导出。通常,它是唯一的导出,但您可以拥有其他导出,前提是它们提供元数据或使用常规名称。

导出名称仅与视图资源有关:自定义元素、附加行为、模板控制器和值转换器。当您将资源导入视图时,编译器需要知道它是什么类型的资源。您可以使用元数据提供此信息,也可以依赖命名约定。因此,如果一个类名为 FooCustomElement,它将知道该导出是一个 CustomElement。AttachedBehavior、TemplateController 和 ValueConverter 也是如此。

此外,如果视图资源不提供元数据并且不遵循命名约定,编译器将假定它是自定义元素。

于 2015-03-17T15:07:39.953 回答