I am getting this strange error from Vue when trying to access get request from api using axios, I am getting "TypeError: Cannot read property 'get' of undefined"
<template>
<div class="home">
<h1>{{ msg }}</h1>
<p>Welcome to your new single-page application, built with <a href="https://vuejs.org" target="_blank">Vue.js</a>.</p>
</div>
</template>
<script>
var Vue = require('vue');
// import axios from "axios";
window.axios=require('axios');
export default {
name: 'Home',
props: {
msg: String
},
component: {
},
mounted: function () {
alert('Hi ');
this.axios.get('https://api.github.com/users')
.then(value => {
alert(value);
});
}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
axios.get
, notthis.axios.get
. You may seethis.axios
used in some examples but in those cases they have storedaxios
onthis
, which doesn't appear to be the case in your code. – Scarificationimport
approach rather than usingrequire
andwindow
. – Scarification