Import a js library into Vuejs

Asked

Viewed 93 times

-1

I’m having trouble importing the js libraries in vuejs I’m always getting the following error on the console.

inserir a descrição da imagem aqui

I am loading them in the index.html file of the public folder

inserir a descrição da imagem aqui

  <script src="/src/js/detect_mobile.js"></script>
  <script src="/src/js/anime.min.js"></script>
  <script src="/src/js/animationjs.js"></script>
  <script src="/src/js/main.js"></script>

1 answer

1

"To import . js files into a file . See, I usually use import (import syntax), see below:

import forms from './assets/js/pages/forms'; // verifique se o diretório está correto

If js has an export, such as an export Function, a function can be imported in this way:

import { nomeDaFuncao } from 'nome-do-arquivo';

And in the.js filename it would look like this:

export function nomeDaFuncao () 
{
 // código
}

That is, in my experience usually the . js file exports something that later in a component . Vue can import in its tag . Note that it does not need to be a function to be exported, you can use export default or module.Xports for objects.

Note: I usually have two separate "applications", the front end in Vuejs and the back end in Laravel, different from your example that in the case I understood it is all in the same place. I haven’t had time to test it, but from what I understand and what I’ve researched, I think it will work. You can edit/correct if I’m wrong, I’m trying to help with what I know."

I put it in quotes because I got the answer to a similar question

Source:Import js file in vuejs and Laravel template

Browser other questions tagged

You are not signed in. Login or sign up in order to post.