async await 异步调用ajax实例

async await 异步调用ajax实例:
检测文件数, 当文件数量>x , 则返回错误信息, 异 则 发请求 进行删除操作

    //检查文件数,如果超过x,则 禁止用户操作
    async checkFileMount(_tableSelection) {
     
      this.filemgtLoading = true;
      let response;
      var params = {
      list: _tableSelection };
      await checkFileCount(params)
        .then(res => {
     
          response = res;
        })
        .catch(e => {
     });
      return response;
    },
    // Delete
    handleDelete() {
     
      this.checkFileMount(this.tableSelection).then(res => {
     
        //条数少于 x 可以操作
        if (res.msg === "COUNTPASS") {
     
          this._handleDelete(this.tableSelection);

          this.filemgtLoading = false;
        } else if (res.msg === "OUTOFCOMPASS") {
     
          this.filemgtLoading = false;
          this.$message({
     
            showClose: true,
            message: "file count > x, you can't do this",
            type: "error"
          });
        }
      });
    },

你可能感兴趣的:(js,vue)