Vue不会更新计算的相关反应数据



有人能解释为什么Vue 3 Composition API在没有强制运行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;
});

计算属性通常不用于更新数据值,它可能会导致问题。在这种情况下,我建议使用一种方法或手表,而不是计算机。看看这是否有效。

最新更新