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

291
Views
What is the correct way to import a js class in vue 3

I want to import a class from the .js file to my component in vue 3 but it throws me an error of

[Vue warn]: Unhandled error during execution of render function at...

Uncaught (in promise) TypeError: $setup.Utils.capitalizeFirstLetter is not a function

I understand that the problem derives from how I use it in the component, I am working on a Laravel 8 application with jetstream and inertia js

My class utils.js

export class Utils {
   capitalizeFirstLetter(str) {
     //code...
   }
}

My component in vue

<template>
     <h2 class="font-semibold text-xl text-gray-800 leading-tight">
        {{ Utils.capitalizeFirstLetter(title) }}
      </h2>
</template>

<script>
import { Utils } from '@/utils/utils.js'

export default {  
  setup() {

      return {
          Utils
      }
  }
};
</script>

Someone who is more expert that can enlighten me

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

0

in the end I understood what I was doing wrong, I had to see some examples in vue 2, you just had to instantiate the class in a variable and if you have it accessible to the methods

<template>
     <h2 class="font-semibold text-xl text-gray-800 leading-tight">
        {{ Util.capitalizeFirstLetter(title) }}
      </h2>
</template>

<script>
import { Utils } from '@/utils/utils.js'

export default {  
  setup() {
      const Util = new Utils;

      return {
          Util
      }
  }
};
</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!