简体   繁体   English

Ember Octane 注销按钮消失

[英]Ember Octane Logout button disappears

I am upgrading to Ember Octane and I modified the template HBS to call the component JS.我正在升级到 Ember Octane,并修改了模板 HBS 以调用组件 JS。 When I use Ember Classic, the Logout button exists and works.当我使用 Ember Classic 时,Logout 按钮存在并且有效。 But, when I convert to Octane then the Logout button disappears.但是,当我转换为 Octane 时,注销按钮就会消失。 o_O o_O

What is the correct way to display a Logout button on the template HBS?在模板 HBS 上显示注销按钮的正确方法是什么? Note: I do not have a component HBS file.注意:我没有 HBS 组件文件。 Is this required in Ember Octane?这在 Ember Octane 中是必需的吗?

Classic Template HBS snippet:经典模板 HBS 片段:

<li><a href="#" onclick={{action "logout"}}>Logout</a></li>

Octane Template HBS snippet: Octane 模板 HBS 代码段:

<li><a href="#" onclick={{on "submit" this.logout}}>Logout</a></li>

Octane Component JS (works with Classic Template, but not Octane Template): Octane 组件 JS(适用于经典模板,但不适用于 Octane 模板):

import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class Navigation extends Component {    

    @service session
    @service currentClient

    @action
    logout(ev) {

        ev.preventDefault();

            this.session.invalidate();
    }
}

The issue here is the improper usage of on modifier.这里的问题是on修饰符的不当使用。 The on modifier has to be used on the element space whereas in your snippet, the on modifier was used as a helper. on修饰符必须用于元素空间,而在您的代码段中, on修饰符用作帮助器。

Should be used like:应该像这样使用:

<button {{on "click" this.logout}}> Logout </button>

This means, we are asking the framework to register the provided function this.logout for the click event.这意味着,我们要求框架为click事件注册提供的 function this.logout

and not as:不是

<button onclick={{on "click" this.logout}}> Logout </button>

This guide should help to migrate from classic event handling to the newest Octane way. 本指南应该有助于从经典事件处理迁移到最新的 Octane 方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM