Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Aurelia 当所有嵌套的子自定义元素都已附加到DOM时,是否在父组件中回调?_Aurelia - Fatal编程技术网

Aurelia 当所有嵌套的子自定义元素都已附加到DOM时,是否在父组件中回调?

Aurelia 当所有嵌套的子自定义元素都已附加到DOM时,是否在父组件中回调?,aurelia,Aurelia,我在视图中添加了一个组件componentA。它由componentA.js和componentA.html组成。现在componentA.html包含两个自定义元素customElement1和customElement2。此外,customElement1还包含一个自定义元素customElement1-1 componentA.html 当所有嵌套的自定义元素都已附加到DOM时,是否还有一个附加的钩子可以从组件a调用?我使用TaskQueue找到了一个解决方案。有关更多信息,请参阅 微任务

我在视图中添加了一个组件
componentA
。它由
componentA.js
componentA.html
组成。现在
componentA.html
包含两个自定义元素
customElement1
customElement2
。此外,
customElement1
还包含一个自定义元素
customElement1-1

componentA.html
当所有嵌套的自定义元素都已附加到DOM时,是否还有一个附加的钩子可以从组件a调用?

我使用
TaskQueue
找到了一个解决方案。有关更多信息,请参阅

微任务允许您推迟在下一个事件中执行的任务 循环或勾选。当您将一个微任务排队时,您正在为此进行调度 在当前执行后立即执行的特定任务 剧本

组件a.js 通过在上面添加代码,将生成以下输出:

componentA - activate
customElement1 - activate
customElement1-1 - activate
customElement2 - activate
componentA - Hello world

我使用
TaskQueue
找到了一个解决方案。有关更多信息,请参阅

微任务允许您推迟在下一个事件中执行的任务 循环或勾选。当您将一个微任务排队时,您正在为此进行调度 在当前执行后立即执行的特定任务 剧本

组件a.js 通过在上面添加代码,将生成以下输出:

componentA - activate
customElement1 - activate
customElement1-1 - activate
customElement2 - activate
componentA - Hello world

简言之,不是。这个GitHub问题讨论了一个类似的问题,可能会有所帮助。简言之,不是。这个GitHub问题讨论了一个类似的问题,可能会有所帮助。有趣!这很聪明-组件是否总是在当前执行循环期间附加?或者这类似于setTimeout,您希望到时候可以连接到它吗?据我所知,
queueMicroTask
方法将任务添加到队列的末尾,在那里任何
激活
,等等。。。嵌套组件或元素的挂钩已在队列中。然而,我不太确定。这就是为什么我希望有人能确认这个解决方案,这样我就可以接受答案了。真有趣!这很聪明-组件是否总是在当前执行循环期间附加?或者这类似于setTimeout,您希望到时候可以连接到它吗?据我所知,
queueMicroTask
方法将任务添加到队列的末尾,在那里任何
激活
,等等。。。嵌套组件或元素的挂钩已在队列中。然而,我不太确定。这就是为什么我希望有人能确认这个解决方案,这样我就可以接受答案。
componentA - activate
customElement1 - activate
customElement1-1 - activate
customElement2 - activate
---
Need to call componentA here, but all custom elements have to be attached to DOM
import {TaskQueue} from 'aurelia-framework';

@inject(TaskQueue)

export class ComponentA {
    constructor(TaskQueue) {
        this.tq = TaskQueue;
    }

    attached() {
        this.tq.queueMicroTask(() => {
            console.log('Hello world');
        });
    }
}
componentA - activate
customElement1 - activate
customElement1-1 - activate
customElement2 - activate
componentA - Hello world