kingcoyote85
kingcoyote85
NNuxt
Created by kingcoyote85 on 7/2/2024 in #❓・help
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')
2 replies