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

274
Visualizações
External JS file not working after being first load VUE

Im trying to build single page app using Vue + inertia + laravel. I have an html template that include external js file. When integrating the template with vue, i notice that, the js only run only once after the page is refresh and not applied to the other page (when navigate using router-link)

i tried some method:

A. add the js script within vue template using mounted

mounted() {
        let appscript = document.createElement("script");
        appscript.setAttribute(
            "src",
            "/dist/js/app.js"
        );
        document.head.appendChild(appscript);
    }

B. Add the js script using meta info

metaInfo: {
    script: [
      {
        src: "/dist/js/app.js",
        async: true,
        defer: true,
      },
    ],
  },

here is my blade file

<!DOCTYPE html>
<html lang="en" class="light">

<head>
    <meta charset="utf-8">
    <link href="/dist/images/logo.svg" rel="shortcut icon">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
        CollaborApps
    </title>
    <link rel="stylesheet" href="{{ asset('dist/css/app.css') }}" />
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    <script type="application/javascript" src="{{ asset('/js/app.js') }}" defer></script>
    <script type="application/javascript" src="{{ asset('/dist/js/app.js') }}" defer></script> <- this is the external js
    @routes
</head>

<body class="main">
    @inertia
</body>

</html>

How to integrate javascript file with vue SPA?

about 4 years ago · Juan Pablo Isaza
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