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

214
Vistas
In Vue 3.* how to pass ref object itself into an event handler with template syntax?
<script setup>
 import { ref } from 'vue'

 const foo = ref(1)
 
 function changeSth(sth, val) {
   sth.val = val;
   // an error trigger, because ref object is unwrapped, sth is just a plain value
 }

</script>

<template>
<button @click="changeSth(foo, 2)">click me change sth.</button>
</template>

I wanna pass ref object foo into function changeSth。 so that I can reuse changeSth to do something like changeSth(foo) changeSth(bar). But now I can only get the value of ref object. So, how to pass ref object itself into event handler like changeSth with template syntax.

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

0

Try like following:

<template>
 <button @click="changeSth('foo', 2)">click me change sth.</button>
   {{ foo }}
</template>

<script setup>
  import { ref } from 'vue'

  const foo = ref(1)

  function changeSth(sth, val) {
    this[sth] = val
  }
</script>
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