将自定义属性传递到Aurelia组件

Jos*_*ale 5 aurelia

我在将属性传递到自定义组件时遇到了一些麻烦.我尝试通过以下方式声明我的组件:

<require from="../components/project-documents"></require>

<project-documents projectId="testing123"></project-documents>
<project-documents projectId.bind="project.Name"></project-documents>
Run Code Online (Sandbox Code Playgroud)
import {customElement, bindable} from "aurelia-framework";
import {autoinject} from "aurelia-dependency-injection";

@customElement("project-documents")
export class ProjectDocuments {

    @bindable projectId:string;

    attached() {
        alert(this.projectId);
    }
}
Run Code Online (Sandbox Code Playgroud)

调用警报时,undefined是我从中获取的值.另外,是否需要customElement装饰器?

小智 7

不要使用camelCase作为属性,请尝试使用dash-case.

试试这个:

<project-documents project-id="testing123"></project-documents>
<project-documents project-id.bind="project.Name"></project-documents>
Run Code Online (Sandbox Code Playgroud)

根据aurelia约定,dash-case'd属性将在ViewModel中转换为camelCase变量,因此您的VM已经很好了.