Vue does not update related reactive data on computed

Viewed 21

Can anyone explain why Vue 3 Composition API doesn't update related reactivity data without forced run in setTimeout?

const isLoaded = ref(true);

const tradeInstrumentFiltered = computed(() => {
  const _tradeInstrumentsSortAndLimited =
    tradeInstrumentsSortAndLimited[props.tradeInstrumentType];
  _tradeInstrumentsSortAndLimited.forEach((ti) => {
    if (!ti.isTracking) {
      if (!isLoaded.value) isLoaded.value = true;
      ti.trackQoute();
    }
  });
  // Work well
  setTimeout(() => (isLoaded.value = false));
  // Doesn't work
  // isLoaded.value = false
  return _tradeInstrumentsSortAndLimited;
});
1 Answers

A computed property is generally not used for updating data values and it can cause issues. I would suggest using a method or a watch instead of a computed in this case. And see if that works.

Related