我正在开发高度依赖@vue/composition-api
的代码库。代码中有几个地方嵌套了computed
和watch
调用。一个例子:
const refA = ref<number | null>(null);
const refB = ref<number | null>(null);
const onClick = () => {
refA.value = 5;
};
watch(refA, (newValue) => {
if (newValue === null) {
return;
}
const {
result,
} = useSomeComposable(newValue);
watch(result, (newResultValue) => {
refB.value = newResultValue;
});
});
我的问题是,如果这是推荐的方法,还是不应嵌套可组合项?这样做有什么弊端吗?例如。由于某些引用,GC无法清理回调函数?是否有一种简单的方法来检查watch / compute回调中的临时引用是否仍在内存中?