Javascript承诺:TypeError:无法读取未定义的属性“ then”

时间:2020-04-22 22:55:08

标签: javascript reactjs promise

我试图使getVideos()异步,然后在函数filterVideos中调用并使用其axios调用的结果。但是,这些诺言给我带来了麻烦。

getVideos

getVideos() {
    let myFirstPromise = new Promise((resolve) => {
      const url = process.env.REACT_APP_MIDDLEWARE_URL + "/api/videolist";
      const options = {
        headers: {
          Authorization: "Bearer " + localStorage.getItem("userToken"),
        },
      };
      axios.get(url, options).then(
        (res) => {
          this.setState({
            video: res.data.videos[0],
            videos: res.data.videos,
          });
          console.log(this.state.videos);
          resolve(res);
        },
        (error) => {
          if (error.response.status === 401) {
            this.props.signOut();
          }
        }
      );
    });
  }

filterVideos

filterVideos() {
    let completed = true;
    this.getVideos().then((res) => {
      res.forEach((video) => {
        if (video.status != "COMPLETED") {
          completed = false;
        }
      });
    });
    if (completed === false) {
      this.waitForCompleted();
    }
  }

0 个答案:

没有答案