欢迎各位兄弟 发布技术文章
这里的技术是共享的
1) import {tap} from 'rxjs/internal/operators';
2) .do() 替换为 .pipe(tap())
do(nextOrObserver: function, error: function, complete: function): Observable
If you are using as a pipeable operator, do
is known as tap
!
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { of } from 'rxjs';
import { tap, map } from 'rxjs/operators';
const source = of(1, 2, 3, 4, 5);
// 使用 tap 透明地打印 source 中的值
const example = source.pipe(
tap(val => console.log(`BEFORE MAP: ${val}`)),
map(val => val + 10),
tap(val => console.log(`AFTER MAP: ${val}`))
);
// 'tap' 并不转换值
// 输出: 11...12...13...14...15
const subscribe = example.subscribe(val => console.log(val));
来自 https://rxjs-cn.github.io/learn-rxjs-operators/operators/utility/do.html