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

181
Vistas
onUpdated is not called with vuejs 3 with render function

I am facing a problem using the onUpdated lifecycle hook in Vuejs3 Composition API. It is not called when a reactive value is updated. I have reproduced the issue with a very simple app. It has one child component:

<script setup lang="ts">
import { h, ref, onUpdated } from 'vue'

const open = ref(false)

const toggle = () => {
    open.value = !open.value
}

defineExpose({ toggle })

onUpdated(() => {
    console.log("Updated")
})

const render = () =>
    open.value ? h(
        'DIV',
        "Child Component"
    ) :
        null
</script>

<template>
    <render />
</template>

Then this component is used by the app:

<script setup lang="ts">
import { ref } from 'vue'
import Child from './components/Child.vue'
const menu = ref(null)
</script>

<template>
  <main>
    <button @click="menu.toggle()">Click Me</button>
    <Child ref="menu" />
  </main>
</template>

<style>
</style>

But when the button is clicked in the app, although the "Child Component" text is shown, proving that the render function is called, the onUpdated callback is not executed.

This must have something to do with the way the render function is called, or the conditional rendering because if I use v-if in a template instead, it works fine. But in my case, I do need an explicit render function.

Can anyone help?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is probably a bug in <script setup>, as that same code works in setup().

A workaround is to switch to setup() if you need to use onUpdated():

<script lang="ts">
import { h, ref, onUpdated } from 'vue'

export default {
  setup(props, { expose }) {
    const open = ref(false)

    const toggle = () => {
        open.value = !open.value
    }

    expose({ toggle })

    onUpdated(() => {
        console.log("Updated")
    })

    const render = () => open.value ? h('DIV', "Child Component") : null

    return render
  }
}
</script>

demo

about 4 years ago · Juan Pablo Isaza Denunciar
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