チェーンコール方式

チェーン呼び出し (1 つのメソッドで複数のインターフェース getUserInfo および getIfVote インターフェース名を呼び出す)

注: インターフェイスのパラメータを前のインターフェイスから取得する必要がある場合は、上記の方法または以下の方法を使用できます。

方法 1:

   getUserInfoData() {
      getUserInfo({})
        .then((res) => {
          console.log(res);
          if (res.status == 200) {
            console.log(res, "============>>>1");
            _this.userInfo = res.data.data ? res.data.data : {};
          }
          return getIfVote({ userId: res.data.data.id });
        })
        .then((res) => {
          if (res.status == 200) {
            console.log(res, "=================2");
            if (res.data == false) {
              _this.isShow = true;
            } else {
              _this.isFalse = true;
            }
          }
        });
}

方法 2: 

getUserInfoData() {
      getUserInfo({}).then((res) => {
        console.log(res);
        if (res.status == 200) {
          console.log(res, "============>>>1");
          _this.userInfo = res.data.data ? res.data.data : {};
          _this.getIfVoteData(_this.userInfo.id);
        }
      });
    },

 getIfVoteData(userId) {
      getIfVote({ userId }).then((res) => {
        if (res.status == 200) {
          console.log(res, "=================2");
          if (res.data == false) {
            _this.isShow = true;
            _this.getDataList();
          } else {
            _this.isFalse = true;
            _this.getVoteStatisticsNumber(userId);
          }
        }
      });
    },

おすすめ

転載: blog.csdn.net/qq_48294048/article/details/130381849