我想知道是否可以更改 Aurelia 中可绑定(bind)的名称(HTML 中的属性名称)。由于我们在当前项目中使用的编码标准,我们使用的属性名称非常难看,例如:m-data="someData"
。我们为所有类成员添加 m
前缀。我知道我可以将它用于类,因此自定义元素名称是可自定义的,但我也可以对可绑定(bind)项执行此操作吗?
例如:
// 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;
}
结果如下:
<!-- index.html -->
<my-component m-data.bind="someData"></my-component>
所以我想做但不起作用的是:
@customElement('my-component')
export class clsMyComponent {
@bindable({name: 'data'}) mData;
}
我找不到任何相关内容,我知道你可以设置双向绑定(bind)、默认值等内容。但不是名称对吗?任何帮助将不胜感激!
最佳答案
经过一番研究,我找到了这个问题的正确答案。如 Aurelia docs 中所述(搜索“可绑定(bind)签名”)。您可以这样设置属性名称:
@customElement('my-component')
export class clsMyComponent {
@bindable({attribute: 'data'}) mData;
}
生成的 HTML:
<my-component data.bind="someData"></my-component>
关于Aurelia:更改可绑定(bind)的名称(属性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44150374/