Watch with props Vue3

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 .

1 answer

  • answered 2021-10-25 03:01 huan feng

    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);
      }
    );
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum