我想在一个HTML文件中运行RxJ代码片段。下面的示例运行
<!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 ()替换它,它就不能工作了。
https://unpkg.com/browse/rxjs@7.5.4/dist/bundles/rxjs.umd.js
所以很明显我不能直接替换。
发布于 2022-04-07 18:52:33
对于unpkg,应该是:https://unpkg.com/rxjs@7.5.5/dist/bundles/rxjs.umd.js
以下是解决方案:
<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>https://stackoverflow.com/questions/71343473
复制相似问题