先获取token,再根据token获取用户信息

  1. // html
  2. <button id="btn">获取用户信息</button>
  1. import axios from "axios"
  2. import { from, fromEvent } from "rxjs"
  3. import { pluck, concatMap } from "rxjs/operators"
  4. const button = document.getElementById("btn")
  5. fromEvent(button, "click")
  6. .pipe(
  7. concatMap(event =>
  8. from(axios.get("http://localhost:3005/token")).pipe(
  9. pluck("data", "token")
  10. )
  11. ),
  12. concatMap(token =>
  13. from(axios.get("http://localhost:3005/userInfo")).pipe(pluck("data"))
  14. )
  15. )
  16. .subscribe(console.log)