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

247
Views
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 answers
Answer question

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 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!