本文介绍了如何更改Aurelia-App查找的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用

初始化了aurelia

<body aurelia-app>
   ...
</body>

入门指南( http://aurelia.io/get-started.html )表示,这将,默认情况下,尝试加载app.jsapp.html

如何告诉aurelia加载main.js和main.html?

如果我执行<body aurelia-app="main">,则仅访问main.js,并且不显示视图.

解决方案

aurelia-app属性提供值时,Aurelia将加载该模块并调用此模块导出的configure方法.在文档中对此进行了解释.

您的配置必须告诉Aurelia为应用程序根目录加载哪个模块.这是文档中的示例:

import {LogManager} from 'aurelia-framework';
import {ConsoleAppender} from 'aurelia-logging-console';

LogManager.addAppender(new ConsoleAppender());
LogManager.setLevel(LogManager.logLevel.debug);

export function configure(aurelia) {
  aurelia.use
    .defaultBindingLanguage()
    .defaultResources()
    .history()
    .router()
    .eventAggregator()
    .plugin('./path/to/plugin');

  aurelia.start().then(a => a.setRoot('app', document.body));
}

您期望发生的不是实际行为.设置属性的值会将Aurelia指向配置模块,该配置模块会将Aurelia指向应用程序根.对于您的情况,您可能需要执行以下操作:

index.html

...
<body aurelia-app="configuration">
...

src\configuration.js

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

  aurelia.start().then(a => a.setRoot('main', document.body));
}

然后将按预期加载src\main.jssrc\main.html(嗯,实际上是dist\main.jsdist\main.html,但是您正在编辑的文件位于src目录中)./p>

I've initialised aurelia with

<body aurelia-app>
   ...
</body>

The getting started guide (http://aurelia.io/get-started.html) says that this will, by default, try to load up app.js and app.html

How can I tell aurelia to load up main.js and main.html?

if I do <body aurelia-app="main"> only main.js is accessed and the view isn't shown.

解决方案

When you supply a value for the aurelia-app attribute, Aurelia will load that module and call the configure method that is exported by this module. This is explained in the documentation.

Your configuration must tell Aurelia which module to load for the app root. Here is the example from the documentation:

import {LogManager} from 'aurelia-framework';
import {ConsoleAppender} from 'aurelia-logging-console';

LogManager.addAppender(new ConsoleAppender());
LogManager.setLevel(LogManager.logLevel.debug);

export function configure(aurelia) {
  aurelia.use
    .defaultBindingLanguage()
    .defaultResources()
    .history()
    .router()
    .eventAggregator()
    .plugin('./path/to/plugin');

  aurelia.start().then(a => a.setRoot('app', document.body));
}

What you're expecting to happen isn't the actual behavior. Setting the value of attribute points Aurelia to a configuration module that will point aurelia to the app root. In your case, you might want to do something like this:

index.html

...
<body aurelia-app="configuration">
...

src\configuration.js

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

  aurelia.start().then(a => a.setRoot('main', document.body));
}

And then src\main.js and src\main.html will be loaded as you expect (well, actually it will be dist\main.js and dist\main.html, but the files you're editing are in the src directory).

这篇关于如何更改Aurelia-App查找的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:49