[英]Ember Octane upgrade: how to handle eslint error no-action
This is related to: Ember Octane Upgrade How to pass values from component to controller这与: Ember Octane Upgrade How to pass values from component to controller有关
In the ../templates/change-password.hbs file, I am receiving the following eslint error:在 ../templates/change-password.hbs 文件中,我收到以下 eslint 错误:
Do not use
action
as {{action ...}}.不要将
action
用作 {{action ...}}。 Instead, use theon
modifier andfn
helper.相反,使用
on
修饰符和fn
助手。 no-action不行动
Code:代码:
<Clients::ChangePasswordForm @chgpwd={{this.model}} @changePassword={{action 'changePassword'}} @errors={{this.errors}} />
The accepted answer instructed me to use that syntax.接受的答案指示我使用该语法。 Is there a different way I should be handling this or should I ignore the error?
是否有不同的方式来处理这个问题,或者我应该忽略错误?
In Ember Octane, linters are updated to encourage the use of on
modifier and fn
helper instead of action
helper & modifier.在 Ember Octane 中,linter 已更新,以鼓励使用
on
修饰符和fn
助手,而不是action
助手和修饰符。 The action
modifier is used to bind the proper this
context to the function. action
修饰符用于将正确的this
上下文绑定到函数。 With Octane, @action
decorators are the recommended way to bind the context to any method.使用 Octane,
@action
装饰器是将上下文绑定到任何方法的推荐方式。
In your case, since you are passing the changePassword
as a closure action to the component Clients::ChangePasswordForm
, the recommended way to pass a function to a component is as follow:在您的情况下,由于您将
changePassword
作为闭包操作传递给组件Clients::ChangePasswordForm
,因此将函数传递给组件的推荐方法如下:
<Clients::ChangePasswordForm
@chgpwd={{this.model}}
@changePassword={{this.changePassword}}
@errors={{this.errors}}
/>
in case, you need to pass any argument (say, this.argument
) along with the function, use fn
helper:如果您需要将任何参数(例如
this.argument
)与函数一起传递,请使用fn
助手:
<Clients::ChangePasswordForm
@chgpwd={{this.model}}
@changePassword={{fn this.changePassword this.argument}}
@errors={{this.errors}}
/>
Since you've already tagged your action with @action
decorator .由于您已经使用
@action
装饰器标记了您的操作。 You are good to go.你已准备好出发。
Here is the official guide on how to upgrade from classic event handlers to Octane recommended way这是有关如何从经典事件处理程序升级到 Octane 推荐方式的官方指南
The lint message can be more helpful and there is already an issue opened on ember-template-lint
repo to expose more useful error message while consuming classic action
helper. lint 消息可能更有帮助,并且在
ember-template-lint
库上已经打开了一个问题,以在使用经典action
助手时公开更有用的错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.