防抖函数

59 阅读1分钟
//防抖函数
export const debounce = (fn, wait, val) => {
    var timer = null;
    return function () {
      if (timer) {
        clearTimeout(timer);
        timer = null;
      }
      timer = setTimeout(() => {
        fn(this, val);
      }, wait || 300);
    };
  };
    delete:debounce((that)=>{
      const index = that.tableData.indexOf(that.clickRow);
      if (that.clickRow.targetEvadataId) {
        deleteSingle({
          evaluateInstanceId: that.evaluateInstanceId,
          targetEvadataId: that.clickRow.targetEvadataId,
        })
          .then((res) => {
            if (res.data.code === 200) {
              that.tableData.splice(index, 1);
              that.$message.success("删除成功");
            }
          })
          .catch((error) => {
            this.$message(error);
          });
      } else {
        that.tableData.splice(index, 1);
      }
    })