首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用unpkg.com CDN运行RxJs

使用unpkg.com CDN运行RxJs
EN

Stack Overflow用户
提问于 2022-03-03 20:32:48
回答 1查看 126关注 0票数 0

我想在一个HTML文件中运行RxJ代码片段。下面的示例运行

代码语言:javascript
复制
<!DOCTYPE html>
<!--
Created using JS Bin
http://jsbin.com

Copyright (c) 2022 by anonymous (http://jsbin.com/gemebopifu/1/edit)

Released under the MIT license: http://jsbin.mit-license.org
-->
<meta name="robots" content="noindex" />
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width" />
        <title>RxJS 5 Operators</title>
        <script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.3/dist/global/Rx.umd.js"></script>
    </head>
    <body>
        <script id="jsbin-javascript">
            //emit value every 1s
            const source = Rx.Observable.interval(1000);
            //sample last emitted value from source every 2s
            const example = source.sample(Rx.Observable.interval(2000));
            //output: 2..4..6..8..
            const subscribe = example.subscribe((val) => console.log(val));
        </script>
    </body>
</html>

但是,如果我用unpkg CDN ()替换它,它就不能工作了。

代码语言:javascript
复制
https://unpkg.com/browse/rxjs@7.5.4/dist/bundles/rxjs.umd.js

所以很明显我不能直接替换。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-07 18:52:33

对于unpkg,应该是:https://unpkg.com/rxjs@7.5.5/dist/bundles/rxjs.umd.js

以下是解决方案:

代码语言:javascript
复制
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>RxJS 5 Operators</title>
    <script src="https://unpkg.com/rxjs@7.5.5/dist/bundles/rxjs.umd.js"></script>
</head>
<body>
    <script id="jsbin-javascript">
        //emit value every 1s
        const source = window.rxjs.interval(1000);
        //sample last emitted value from source every 2s
        const example = window.rxjs.interval(2000);
        //output: 2..4..6..8..
        const subscribe = example.subscribe((val) => console.log(val));
    </script>
</body>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71343473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档