Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!