【问题标题】:Is there a way to import rxjs into a plain js web custom component?有没有办法将 rxjs 导入普通的 js web 自定义组件?
【发布时间】:2019-08-18 13:22:54
【问题描述】:

我正在尝试使用纯 js 创建 Web 自定义组件。我想使用 rxjs 和 observables 从我也使用 python 金字塔创建的 REST 端点获取 json 内容。但是,当我导入 rxjs 时,会抛出一个错误 - 'TypeError: global is undefined'。

import 'https://unpkg.com/@reactivex/rxjs@6.0.0/dist/global/rxjs.umd.js';

也试过了:

import 'https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js';

我根本不想使用 npm。

【问题讨论】:

  • 了解如何。我应该将 url 放入脚本标签中,然后在 js 文件中使用:js const { Observable, from } = rxjs;

标签: javascript rxjs custom-element


【解决方案1】:
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js"></script>

然后:

const { Observable, from } = rxjs;

【讨论】:

    猜你喜欢
    • 2021-09-30
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2019-10-31
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多