Home > Software engineering >  Watch with props Vue3
Watch with props Vue3

Time:10-26

I want to try update modelValue and chang value in datepicker

watch(range, (range) => {
  emit("update:modelValue", range);
  console.log("update:modelValue", range)
  
});
watch(() => props.modelValue,
  (modelValue) => {
    range.value = {
      start: modelValue.start,
      end: modelValue.end,
    };
  }
);

is working but is delay and show error [Vue warn]: Maximum recursive updates exceeded in component .

CodePudding user response:

Why you need the first watch?

watch(() => props.modelValue,
  (modelValue) => {
    // Maybe some if condition check to avoid unnecessary calls
    range.value = {
      start: modelValue.start,
      end: modelValue.end,
    };
    emit("update:modelValue", range);
  }
);
  • Related