Calling a composable from inside computed doesn't call onMounted

I'm using Nuxt3 and Vue3 and having trouble getting my composables to work properly. My composable contains an onMounted() call, but that call only seems to work in certain situations. My composable, useSableCan, calls setInterval inside onMounted, and clears in onUnmounted. When I call this composable from the root of my SFC steup script, the onMounted works and logs to console. But when I call it from inside a computed function, nothing... here is my code. Any thoughts?
const cageData = computed(() => {
return cages.value.map((c) => {
let data: any = { cage: c }

// onMounted will NOT be called from these instances of useSableCan
if (settings.value.x_axis) {
data['xBreaks'] = useSableCan(`m 9 ${c} 41 1 1 B`)
data['xMask'] = useSableCan(`m 9 ${c} 41 1 9 B`)
}

return data;
});
});

// onMounted will be called from this instance of useSableCan
const command = useSableCan('10 1 71')
const cageData = computed(() => {
return cages.value.map((c) => {
let data: any = { cage: c }

// onMounted will NOT be called from these instances of useSableCan
if (settings.value.x_axis) {
data['xBreaks'] = useSableCan(`m 9 ${c} 41 1 1 B`)
data['xMask'] = useSableCan(`m 9 ${c} 41 1 9 B`)
}

return data;
});
});

// onMounted will be called from this instance of useSableCan
const command = useSableCan('10 1 71')
1 Reply
kingcoyote85
kingcoyote85OP5mo ago
I looked into this more and it seems that you cannot call lifecycle hooks inside a computed function. I may have to manage the mount and unmount manually.
Want results from more Discord servers?
Add your server