Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
Vue3 computed property changing its value inside onMounted hook

I have just been using and learning Vue for a week, and developing a small vue3 application using a CDN because that's the requirement. I'm implementing using a composition api. I have a computed property which is shown below.

Note that state.allCvls is a reactive variable which is a result of an axios.get call from a rest api.

...
const allCvlCount = computed (() => {
    return state.allCvls.length; // This value is generated from an axios call from a restapi.
});
...

onMounted (() => {
    console.log(allCvlCount);
    console.log(allCvlCount.value);
})

When I try to print the object and its value property, they have different values as shown in the image below.

enter image description here

I tried to create a test case and its not behaving the same way as above. Where can I start debugging to pin down the cause of this discrepancy.

Here is my test case which is working fine.

<!DOCTYPE html>
<html>
<head>
<style>
#app {
  height: 400px;
}
</style>
</head>
<body>
<div id="app">
  <!-- <v-chart autoresize :option="myOptions"/> -->
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<script>
    const { createApp, reactive, computed, onMounted } = Vue
    const app = createApp({
        setup() {
            const state = {
                myReactiveVar: [{'name': 'foo', 'count': 5}, {'name': 'bar', 'count': 3}, {'name': 'xyz', 'count': 8}]
            }
            const myComputedProperty = computed(() => {
                return state.myReactiveVar.filter(e => e.count <= 5).length;
            });

            onMounted(() => {
                console.log(myComputedProperty);
                console.log(myComputedProperty.value);
            });
            
            return {
                state,
                myComputedProperty
            };
        }
    })
    .mount("#app");
</script>
</body>
</html>

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda