首页 > 其他分享 >vue3 使用watch 监听多个数据

vue3 使用watch 监听多个数据

时间:2022-12-06 13:25:47浏览次数:47  
标签:end form watch value break start key vue3 监听

// 监听时间选择
watch(
  [
    internalSubmTimer,
    internalTimer,
    externalSubmTimer,
    externaTimer,
    callbackTimer,
  ],
  (newValue, oldValue) => {
    Object.keys(newValue).forEach(function (key) {
      if (newValue[key]) {
        disposeTime(key, newValue[key]);
      } else {
        disposeTime(key, newValue[key]);
      }
    });
  }
);

// 统一处理时间
const disposeTime = (Timetype, timers) => {
  const [start, end] = timers || ["", ""];
  let timeobj = {
    0: "内审提交时间",
    1: "内审时间",
    2: "外审提交时间",
    3: "外审时间",
    4: "回调时间",
  };
  switch (timeobj[Timetype]) {
    case "内审提交时间":
      form.value.internalAuditSubmissionStartTime = start;
      form.value.internalAuditSubmissionEndTime = end;
      break;
    case "内审时间":
      form.value.internalAuditStartTime = start;
      form.value.internalAuditEndTime = end;
      break;
    case "外审提交时间":
      form.value.externalAuditSubmissionStartTime = start;
      form.value.externalAuditSubmissionEndTime = end;
      break;
    case "外审时间":
      form.value.externalAuditStartTime = start;
      form.value.externalAuditEndTime = end;
      break;
    case "回调时间":
      form.value.notifyStartTime = start;
      form.value.notifyEndTime = end;
      break;
    default:
  }
};

  因为后台表格筛选用到了五六个  el-date-picker  时间日期选择器,所以为了方便,就这样统一处理了

标签:end,form,watch,value,break,start,key,vue3,监听
From: https://www.cnblogs.com/llive/p/16954942.html

相关文章