shayloyuki

科技是第一生产力

 

then catch 简易写法

  1. 为了捕获上一步 then 中的 promise 结果,必须在上一步 return
  2. 关闭遮罩层,放在 finally 中,即无论成功或失败都要执行;
    archiveAction(actionType, row) {
      const ids = row && row.id ? row.id : this.ids;
      const tip = row && row.id ? `“${row.projectName}”` : "所勾选的";
      const actionLabel = actionType === "archive" ? "归档" : "解档";
      this.$modal
        .confirm(`是否确认${actionLabel}${tip}项目?${actionLabel}后可编辑`)
        .then(async () => {
          this.$modal.loading(`正在${actionLabel},请稍后……`);
          return actionType === "archive"
            ? await project.archiveProject(ids)
            : await project.unArchiveProject(ids);
        })
        .then((res) => {
	// 这里为了捕获上一步 then 中的 promise 结果,必须在上一步 return
          this.$modal.msgSuccess(`${actionLabel}成功`);
          this.getList();
        })
        .catch((err) => {
          console.log(err);
        })
        .finally(() => {
          this.$modal.closeLoading();
        });
    },

posted on 2024-07-12 17:14  shayloyuki  阅读(4)  评论(0编辑  收藏  举报

导航