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

290
Views
¿Cómo uso el complemento personalizado en <script setup> en vue 3?
//TestPlugin.js const randomValue = (min, max) => { min = Math.ceil(min); max = Math.floor(max); const random = Math.floor(Math.random() * (max - min + 1)) + min; console.log(random); }; export default { install(Vue) { Vue.config.globalProperties.$randomValue = randomValue; }, };
 //App.vue <template> <button>event</button> </template>

Este código es un ejemplo. Quiero llamar a la función randomValue dentro de <script setup> y ponerla en un botón en lugar de <buton@click="$randomValue(0, 20)">

El siguiente es un ejemplo de lo que quiero hacer.

 //App.vue <template> <button @click="random">event</button> </template> <script setup> const random = $randomValue(0,10); </script>

¿Cómo hago esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Encontré la respuesta yo mismo...

 //TestPlugin.js export default { install(Vue) { Vue.config.globalProperties.$randomValue = randomValue; Vue.config.globalProperties.$valueCheck = valueCheck; Vue.provide("plugins", { valueCheck, randomValue }); }, };
 //App.vue <script setup> import { inject } from 'vue'; const { valueCheck, randomValue } = inject("plugins"); const hello = () => { randomValue(0,10); } </script>

Vue.provide("plugins", { valueCheck, randomValue }); e import { inject } from 'vue'; const { valueCheck, randomValue } = inject("plugins");

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!