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

296
Views
Vuejs require("axios") en el archivo .js, require no está definido

Estoy usando vuejs y estoy tratando de hacer una solicitud GET a mi API. Estoy usando axios, pero no puedo importarlo, si uso require para importar axios obtengo este error: Error de Uncaught ReferenceError: require is not defined .

Este es mi archivo vuetest.js:

 const axios = require("axios"); new Vue({ el: "#rentalsVue", data() { return { info: null, }; }, mounted() { axios.get("/getRentals").then((response) => (this.info = response)); }, });

Este es el html:

 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> </head> <body> <div id="rentalsVue"> {{ info }} </div> <script src="vuetest.js"></script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto sucede porque require() no existe en JavaScript del lado del navegador/cliente.

Debe importar Axios usando la etiqueta <script> y luego podrá usarlo.

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!