rxjs使用of:举例数据的实例

注意:

安装了

npm install  [email protected] --save

如果按照以下方法调用of方法:会报错找不到of方法的错误。

import React from 'react';
import { Observable } from 'rxjs';
import 'rxjs/add/observable/of'

const FlowPage = () => {

  const source$ = Observable.of(1,2,3);
  source$.subscribe(
    console.log,
    null,
    ()=>console.log('complete')
  )
  return <h1>rxjs学习</h1>;
};

export default FlowPage;

解决方案一:

npm install [email protected] --save

执行结果:

 解决方案二:

  import { of } from 'rxjs';

const source$ = of(1,2,3) source$.subscribe( console.log, null, ()=>console.log('complete') )

 

猜你喜欢

转载自www.cnblogs.com/hibiscus-ben/p/12393997.html