Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
trying to create a prototype to access my Api (Axios) globally in [vue.js 3] and I always get this error: "Cannot read properties of undefined"

the error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'get')

the main files

the axios file

import axios from "axios";

const token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOJQ......";

export default axios.create({
  baseURL: "https://api.themoviedb.org/3",
  headers: {
    authorization: `Bearer ${token}`,
  },
});

the main.js file

import api from "@/data/db";

const app = createApp({});
app.config.globalProperties.$http = api;

the home file

async mounted() {
    const response = await this.$http.get("/movie/550");
    console.log(response);
},
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Check out this sandbox. It logs a promise in the console, doesn't give the undefined error. Try putting your actual key in the db.js file and check if you can make a request to the API.

I think the problem in your code is with this line const app = createApp({});

You need to pass a component with the mounted() hook in it as an object param to the createApp function. Then you need to mount the app.

import api from "@/data/db";
import Home from "@/Home.vue";
const app = createApp(Home);
app.config.globalProperties.$http = api;
app.mount("#app"); // Provide a valid html id that exists in your index.html file
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda