Aic*_*ink 4 aurelia aurelia-binding
我想知道是否可以更改Aurelia中可绑定的名称(HTML中的属性名称).由于我们在当前项目中使用的编码标准,我们使用的属性名称非常难看,例如:m-data="someData".我们为所有班级成员加上前缀m.我知道我可以在课堂上使用它,所以自定义元素名称是可自定义的,但我也可以为bindables做这个吗?
例如:
// my-component.js
// I can use a decorator here to
// change the custom element name, which is great!
@customElement('my-component')
export class clsMyComponent {
@bindable mData;
}
Run Code Online (Sandbox Code Playgroud)
其结果如下:
<!-- index.html -->
<my-component m-data.bind="someData"></my-component>
Run Code Online (Sandbox Code Playgroud)
所以我想做但不起作用的是:
@customElement('my-component')
export class clsMyComponent {
@bindable({name: 'data'}) mData;
}
Run Code Online (Sandbox Code Playgroud)
我在这上面找不到任何东西,我知道你可以设置像双向绑定,默认值等的东西.但是这个名字不对吗?任何帮助,将不胜感激!
因此,经过一些研究,我发现了这个问题的正确答案.如Aurelia文档中所述(搜索'可绑定签名').您可以像这样设置属性名称:
@customElement('my-component')
export class clsMyComponent {
@bindable({attribute: 'data'}) mData;
}
Run Code Online (Sandbox Code Playgroud)
生成的HTML:
<my-component data.bind="someData"></my-component>
Run Code Online (Sandbox Code Playgroud)