【问题标题】:Aurelia: custom elements doesn't render output as expected. Browser doesn't load js file.Aurelia:自定义元素未按预期呈现输出。浏览器不加载 js 文件。
【发布时间】:2016-03-27 11:37:10
【问题描述】:

我正在尝试使用 aurelia 设计自定义元素,但我一遍又一遍地遇到同样的问题:浏览器加载了组件的 html 文件,但没有加载它的兄弟 js 文件。我正在使用 es2016 入门套件 1.0.0-beta.1.2.0、jspm 0.16.15 和 npm 2.11.2

具体来说,考虑一个(非常)简单的例子。该组件(如预期)称为 test ,其 html 和 js 文件分别如下:

test.html:

<template>
<div>Name: ${name}</div>`
</template>`

test.js

import {bindable} from 'aurelia-framework';
export class Test {
@bindable name = "";
}

组件从文件app.html调用,属性名称的值设置在app.js,如下:

app.html:

<template>
<require from="bootstrap/css/bootstrap.css"></require>
<require from="./test.html"></require>

<div class="page-host">
      <test name.bind="name"></test>
</div>
</template>

app.js:

export class Welcome {
   name = 'My Test';
}

让本地服务器运行后,输出很简单:

姓名:

虽然预期的输出是:名称:我的测试。

我注意到的: 1)如果我去谷歌浏览器开发工具的源文件夹 dist ,我看到加载了以下文件:app.html; app.js 和 test.html。 也就是说,test.js 根本不会出现在那里。 2)如果写test.html如下:

 <template bindable="name">
 <div>Name: ${name}</div>
 </template>

我有预期的输出:名称:我的测试

我应该错过了一些我无法弄清楚的非常愚蠢的事情。关于可能发生的事情的任何提示?发送

【问题讨论】:

    标签: javascript file components aurelia


    【解决方案1】:

    当您在导入末尾附加 .html 时,您告诉加载器仅加载 html 文件 -

    <require from="./test.html"></require>
    

    你需要像这样删除它 -

    <require from="./test"></require>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      相关资源
      最近更新 更多