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

288
Views
How do I use the custom plugin in <script setup> in 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>

This code is an example. I want to call the randomValue function within <script setup> and put it in a button instead of <buton@click="$randomValue(0, 20)">

The following is an example of what I want to do.

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

How do I do this?

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

0

I found the answer myself...

//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>

I added Vue.provide("plugins", { valueCheck, randomValue }); and 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!