2

使用以下代码:

import { Aurelia } from "aurelia-framework";

export async function configure(aurelia) {
  aurelia.use.standardConfiguration().developmentLogging();

  await aurelia
    .start()
    .then(a => a.setRoot())
    //.then(a => a.setRoot("app.js", document.body))
    .catch(ex => {
      document.body.textContent = `Bootstrap error: ${ex}`;
    });
}

我收到此错误:

引导错误:错误:未指定应用程序主机。

如果我改用使用.then(a => a.setRoot("app.js", document.body))而不是.then(a => a.setRoot())一切正常。

在 Aurelias 自己的快速入门指南中,他们使用以下代码:

import {Aurelia} from 'aurelia-framework';

export function configure(aurelia: Aurelia) {
    aurelia.use.basicConfiguration();
    aurelia.start().then(() => aurelia.setRoot());
}

如果我切换到use.basicConfiguration我的代码,我仍然会遇到同样的错误。

https://aurelia.io/docs/tutorials/creating-a-todo-app#getting-ready-to-render

Codesandbox 重现:

https://codesandbox.io/s/0x4wvlly90

4

1 回答 1

0

在自动引导中,aurelia-bootstrapper检测具有aurelia-app属性的元素,并根据指定的值,将主条目加载到引导,其中包含有关哪些元素承载这些aurelia-app属性的信息。这就是为什么你可以setRoot()不用任何争论。第一个参数是app.js,第二个参数由上述检测自动提供。

当您像在问题代码块中那样手动引导时,没有关于 root 的信息,因此您看到了错误。因此,提供第二个参数是正确且标准的方法。

于 2019-01-17T00:44:19.067 回答