tes*_*dtv 2 javascript ember.js ember-cli
在 Ember JS 中,假设我有一个定义如下的组件(HBS/JS)
parent.hbs
{{longclaw-sword attack=(action swing)}}
Run Code Online (Sandbox Code Playgroud)
app/components/longclaw-sword.js
export default Ember.Component.extend({
click() {
this.attack();
}
});
Run Code Online (Sandbox Code Playgroud)
使用this.attack()V/s调用关闭操作有什么区别
this.attr.attack()吗?
在哪些情况下使用“attr”?它可以用于参考正常属性还是仅用于操作?
attr 是一种非正式的弃用 afaik。
在即将到来的 Ember 版本中,Octane 属性将专门表示仅 HTML 属性,而args将是 ember-land 中的内容。
将来/现在(如果您想使用辛烷值蓝图(https://github.com/ember-cli/ember-octane-blueprint),上面的内容将是:
@action swing() {
// whatever this does :)
}
<LongclawSword @attack={{this.swing}} />
// in longclaw-sword:
import Component from '@glimmer/component';
export default LongclawSword extends Component {
@action click() {
this.args.attack();
}
}
// or, if you don't need to wrap attack, you can do this inside longclow's template:
<button {{on 'click' this.args.attack}}>click</button>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
162 次 |
| 最近记录: |