问题
In Ember JS, say I have a component defined as below (HBS/JS)
parent.hbs
{{longclaw-sword attack=(action swing)}}
app/components/longclaw-sword.js
export default Ember.Component.extend({
click() {
this.attack();
}
});
Is there any difference between calling the closure action using
this.attack()
V/s this.attr.attack()
?
In which cases is "attr" used ? Can it be used for reference to normal properties OR is it only for actions ?
回答1:
attr is kinda unofficially deprecated afaik.
in the upcoming edition of Ember, Octane, attributes will mean specifically HTML-only attributes, and args will be what is in ember-land.
In the future / Now (if you want to play with the octane blueprint (https://github.com/ember-cli/ember-octane-blueprint), the above would be this:
@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>
来源:https://stackoverflow.com/questions/55657493/ember-invoking-closure-action