首页 > 解决方案 > Vue.js Snotify - 异步触发多个调用

问题描述

以下是我使用 axios 调用远程调用的代码,并根据服务器错误或成功通知中的错误类型向用户显示。这是原始文档的链接。

async getResponseFromServer() {
  if (this.errors.all().length == 0) {
    this.$snotify.clear();

    this.$snotify.async(
      "Getting Data",
      "Loading...",

      () =>
        new Promise((resolve, reject) => {
          return this.getDataCommonResponse()
            .then(function(response) {
              if (response.status && response.type == undefined) {
                resolve({
                  title: response.error,
                  body: "This is the balance",
                  config: {
                    closeOnClick: true,
                    position: SnotifyPosition.centerTop
                  }
                });
              } else {
                reject({
                  title: "Error",
                  body: response.error,
                  config: {
                    closeOnClick: true,
                    position: SnotifyPosition.centerTop
                  }
                });
              }
            })
            .catch(function(error) {});
        })
    );
  }
}

在 GitHub 中也有一个未解决的问题。它说 Snotify 将进行 2 次 API 调用,但会发出多个请求。有没有办法限制单个 API 调用?

有没有办法来解决这个问题?

标签: javascriptvue.jsvuejs2async-awaitaxios

解决方案


推荐阅读