天天看點

關于如何使用rxjs

import { interval } from 'rxjs';

// Create an Observable that will publish a value on an interval
const secondsCounter = interval(1000);
// Subscribe to begin publishing values
secondsCounter.subscribe(n =>
  console.log(`It's been ${n} seconds since subscribing!`));
           

如上所示, 首先引入rxjs,其次定義一個 一秒的循環 函數, 然後調用該函數,并輸出該時間