Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda