fetchapi和rxjs:我看不到回复中的任何数据
我有以下代码,
import { fromEvent } from 'rxjs';
import { debounceTime, map, mergeMap, tap } from 'rxjs/operators';
// Examples: kumar
const url = 'https://gorest.co.in/public/v2/users?name=';
// elem ref
const searchBox = document.getElementById('search');
// streams
const keyup$ = fromEvent(searchBox, 'keyup');
keyup$
.pipe(
map((i: any) => i.currentTarget.value),
debounceTime(500),
mergeMap((v) => fetch(url + v)),
tap((result) => {
console.log('JSON: ', result.json());
})
)
.subscribe((result) => console.log(result));
您可以将其复制并粘贴到 https://stackblitz.com/edit/typescript-adheqt?devtoolsheight=50&file=index.ts ,
但我看不到JSON结果。请帮助,我不明白为什么我看不到任何数据。
I have the following code
import { fromEvent } from 'rxjs';
import { debounceTime, map, mergeMap, tap } from 'rxjs/operators';
// Examples: kumar
const url = 'https://gorest.co.in/public/v2/users?name=';
// elem ref
const searchBox = document.getElementById('search');
// streams
const keyup$ = fromEvent(searchBox, 'keyup');
keyup$
.pipe(
map((i: any) => i.currentTarget.value),
debounceTime(500),
mergeMap((v) => fetch(url + v)),
tap((result) => {
console.log('JSON: ', result.json());
})
)
.subscribe((result) => console.log(result));
You can copy and paste it into https://stackblitz.com/edit/typescript-adheqt?devtoolsheight=50&file=index.ts
But I don't see the JSON result. Please help, I don't understand why I don't see any data.
PS: I don't want to use fromFetch. It's just for learning purposes and I would like to use the fetch api.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON()
返回承诺,因此您仍然需要解决该承诺/可观察的诺言:json()
returns a promise so you still need to resolve that promise/observable :