问题描述
这与以下内容有关:
在../templates/change-password.hbs文件中,我收到以下eslint错误:
In the ../templates/change-password.hbs file, I am receiving the following eslint error:
代码:
<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?
推荐答案
在Ember Octane中,短绒棉已更新为鼓励在修饰符和
fn
助手上使用而不是
action
帮手&修饰符。 action
修饰符用于将正确的 this
上下文绑定到函数。使用Octane,推荐使用 @action
装饰器将上下文绑定到任何方法。
In Ember Octane, linters are updated to encourage the use of on
modifier and fn
helper instead of action
helper & modifier. The action
modifier is used to bind the proper this
context to the function. With Octane, @action
decorators are the recommended way to bind the context to any method.
在您的情况下,由于您要将 changePassword
作为关闭操作传递给组件 Clients :: ChangePasswordForm
,将函数传递给组件的推荐方法如下:
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:
<Clients::ChangePasswordForm
@chgpwd={{this.model}}
@changePassword={{this.changePassword}}
@errors={{this.errors}}
/>
以防万一,您需要传递任何参数(例如, this.argument
)以及该函数,请使用 fn
助手:
in case, you need to pass any argument (say, this.argument
) along with the function, use fn
helper:
<Clients::ChangePasswordForm
@chgpwd={{this.model}}
@changePassword={{fn this.changePassword this.argument}}
@errors={{this.errors}}
/>
由于您已经标记了操作。你已准备好出发。
Since you've already tagged your action with @action
decorator. You are good to go.
这是有关如何从经典事件处理程序升级到Octane推荐方式的
Here is the official guide on how to upgrade from classic event handlers to Octane recommended way
皮棉消息可能会更有用,并且有已经在问题 > ember-template-lint 回购可显示更多有用的错误消息,同时使用经典的 action
助手。
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.
这篇关于Ember Octane升级:如何处理eslint错误无作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!