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

298
Views
Vuejs 3 (API de composición) v-model render [objeto Objeto]

Traté de crear ganchos reutilizables/componibles en vuejs 3 llamados useCounter . La función devuelve el count objetos (ref) y increment . Cuando configuro v-model.number="counter.count" representará [object Object], pero para v-model.number="count" se representará correctamente

Incremento counter.count desde App.vue en increment() también funciona

aplicación.vue

 <script setup> import { ref, computed, unref } from 'vue' import useCount from './useCount.js' const count = ref(5) const counter = useCount({ initialCount: 5 }) const increment = () => { count.value++ // Added counter.count.value++ // Added } console.log("count", count) console.log("counter.count", counter.count) </script> <template> <h1>{{ counter.count }}</h1> <input v-model.number="counter.count" /> <button @click="counter.increment"> Increment useCount </button> <h1>{{ count }}</h1> <input v-model.number="count" /> <button @click="increment"> Increment all </button> </template>

usarContador.js

 import { ref } from 'vue' const useCount = (props = {}) => { const count = ref(props.initialCount ?? 0) const increment = () => { count.value++ } return { increment, count, } } export default useCount

Resultado: Captura de pantalla

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

En {{ count }} se desenvuelve automáticamente , y en v-model se trata como v-model="{value:0}" , por lo que podría solucionarlo destruyendo el valor devuelto del gancho componible:

 <script setup> import { ref, computed, unref } from 'vue' import useCount from './useCount.js' const {count,increment} = useCount({ initialCount: 5 }) </script> <template> <h1>{{ count }}</h1> <input v-model.number="count" /> <button @click="increment"> Increment useCount </button> </template>

MANIFESTACIÓN

about 4 years ago · Santiago Trujillo 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!