gpt4 book ai didi

javascript - Aurelia 功能 globalResources (jspm)

转载 作者:行者123 更新时间:2023-11-30 15:49:57 24 4
gpt4 key购买 nike

在功能和全局资源方面需要一些帮助在 jspm 中使用 aurelia在我的 src 文件夹中我有这个结构

src/
|-- components/
| |-- core/
| | |-- table/

在我的主要 js 中我有 .feature('components')

我有两个 index.js,一个在组件中做

export function configure(config) { 
config.feature('core');
}

核心做事

export function configure(config) { 
config.globalResources([ './table' ]);
}

我从系统 js 得到 http://localhost:5000/core/index.js 404 (Not Found)你能有次级功能吗?或者更好的是我可以拥有这个

|-- src/
|-- components/
| |-- core/

更新

我已经设法让一些东西工作了,有一点要说明:

core/index.js 应该是这样的:

export function configure(config) {
config.globalResources('./table/table'); // I was missing the fact
// I needed folder name AND js file name (without prefix)
}

其次它必须是这个文件夹结构:

src/
|-- core/
| |-- table/

看来您不能在功能中嵌套功能

最佳答案

您可以将一个功能嵌套在一个功能中,您只需要提供完整路径即可。

configure(config)config 参数属于 FrameworkConfiguration 类型,在注册功能时,它从 src 根的 Angular “思考”。

给定这个结构:

src/
|-- main.js
|-- components/
| |-- index.js
| |-- core/
| | |-- index.js
| | |-- table/
| | | |-- index.js
| | | |-- table.js
| | | |-- table.html

您需要以下配置功能:

src/main.js

aurelia.use.feature('components');

src/components/index.js

export function configure(config) {
let params = {}
config.feature('components/core');
}

src/components/core/index.js

export function configure(config) {
config.feature('components/core/table');
}

src/components/core/table/index.js

export function configure(config) {
config.globalResources([ './table' ]);
}

您可以通过从父级向下传递父级路径来使其更具重构性,这样子级就不需要知道自己的绝对路径,如下所示:

src/main.js

aurelia.use.feature('components', params => params.parent = 'components');

src/components/index.js

export function configure(config, configure) {
let params = { parent: '.' };
configure(params);
config.feature(`${params.parent}/core`, params => params.parent = `${params.parent}/core`);
}

src/components/core/index.js

export function configure(config, configure) {
let params = { parent: '.' };
configure(params);
config.feature(`${params.parent}/table`);
}

src/components/core/table/index.js

export function configure(config) {
config.globalResources([ './table' ]);
}

Aurelia 团队似乎也在为此工作,但我不知道当前状态是什么:https://github.com/aurelia/framework/issues/376

关于javascript - Aurelia 功能 globalResources (jspm),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39532888/

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