gpt4 book ai didi

aurelia - 将 humane.js 与 aurelia 结合使用

转载 作者:行者123 更新时间:2023-12-02 09:32:52 24 4
gpt4 key购买 nike

我正在尝试使用 humane.jsaurelia但是我遇到了问题。

看来 humane.js 在创建时向 DOM 添加了一个元素,到目前为止我发现的唯一方法就是像这样强制它......

showMessage(message) {
this.notify = humane.create();
this.notify.log(message);
}

但是,每次调用 showMessage() 时,都会创建一个新的 humane 实例。这会破坏队列,因为每个队列都是单独渲染的。

我尝试将 create() 放入 View 模型的 activate() 方法中,但这似乎也不起作用。

有什么想法吗?

最佳答案

这解决了问题,我创建了一个人性化的自定义元素,然后将其包含在 app.html 中,就像加载指示器在骨架应用程序中一样。

import humane from 'humane-js';
import 'humane-js/themes/original.css!';
import {inject, noView} from 'aurelia-framework';
import { EventAggregator } from 'aurelia-event-aggregator';
import { ApiStatus } from 'resources/messages';

@noView
@inject(EventAggregator)
export class StatusIndicator {

constructor(ea) {
this.ea = ea;
ea.subscribe(ApiStatus, msg => this.showMessage(msg.apistatus));
}

attached() {
this.humane = humane.create();
}

showMessage(message) {
this.humane.log(message);
}
}

重要的部分是attached(),它允许人性化的设置正确工作。

关于aurelia - 将 humane.js 与 aurelia 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30824375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com