灰烬调用关闭动作 [英] Ember invoking closure action

查看:76
本文介绍了灰烬调用关闭动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ember JS中,说我有一个定义如下的组件(HBS / JS)



parent.hbs

  {{longclaw-sword Attack =(action swing)}} 

app / components / longclaw-sword.js

 导出默认Ember.Component.extend({
click(){
this.attack();
}
});

使用
调用关闭操作之间是否有区别.attack() V / s this.attr.attack()



在什么情况下使用 attr?

解决方案

attr是一种非官方弃用的afaik。 p>

在即将发布的Octane Ember版本中,属性将意味着专门用于HTML的属性,而 args 将成为余烬之地。 / p>

将来/现在(如果您想使用辛烷值蓝图( https://github.com/ember-cli/ember-octane-blueprint ),上面就是这样:

  @action swing(){
//这样做:)
}

< LongclawSword @attack = {{ this.swing}} />

//用长爪剑:
import来自 @ glimmer / component的组件;

导出默认值LongclawSword扩展了组件{
@action click(){
this.args.attack();
}
}
// //如果不需要包装攻击,则可以在longclow的模板中执行此操作:
< button {{单击单击 .args.attack}}>点击< / button>


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 ?

解决方案

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>

这篇关于灰烬调用关闭动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆