如何在Aurelia应用程序中使用外部自定义元素(插件)

How to use external custom element (plugin) in Aurelia app?

本文关键字:自定义 外部 元素 插件 Aurelia 应用程序      更新时间:2023-09-26

我在github的repo中定义了一个自定义元素。然后在另一个应用程序中添加jspm install 'd所述元素。

在其他应用中导入该元素的正确方法是什么?当我在应用程序配置中调用aurelia.use.plugin('aurelia-custom-element')时,它说它找不到aurelia-custom-element.js

aurelia-custom-element.html:

<template>
<div>Hello world, from Aurelia custom element!</div>
</template>

aurelia-custom-element.js:

import {customElement, bindable} from 'aurelia-framework';
@customElement('aurelia-custom-element')
export class AureliaCustomElement {
}

index.js:

export * from './aurelia-custom-element';
export function configure(config){
  config.globalResources('./aurelia-custom-element');
}

您放置的aurelia.use.plugin('[here]')应该与您安装的jspm相匹配。

例如,如果github的repo包含你的插件是https://github.com/uavalos/mega-plugin,你会执行jspm install github:uavalos/mega-plugin来安装插件。要加载插件,你需要写aurelia.use.plugin('uavalos/mega-plugin')

如果你分享你的插件的url,我可以提供更具体的帮助。