axios: Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
Hi!
I’m trying to use your library but I get an error:
Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
I was using your example
axios.get('https://api.github.com/users/benjamingeorge')
.then(function (res) {
console.log(res.data);
})
.catch(function(res) {
if(res instanceof Error) {
console.log(res.message);
} else {
console.log(res.data);
}
});
The error happens here. I’m using browserify and chrome 45.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 15
- Comments: 30 (1 by maintainers)
Actually, I can not even reproduce the error now.
If you use vue or another just
And use Axios normally without using
Vue.use(axios)
Everything works fine
@vpiskunov Maybe it’s because you are using the origin axios, not a vue plugin, you should use Vue.prototype.$axios = axios if you want vue’s instance to call it
I was getting this error due to the url being undefined. Was fixed after I addressed that issue.
Any solution? I am also using it with
Vue.use(axios)
isURLSameOrigin.js?142d:61 Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
Perhaps could be about the way we import it into VueJS? There doesn’t seem to be any docs on how to properly import it to Vue, especially when using Webpack…Any ideas greatly appreciated!
Would you mind sharing what you did wrong for future reference?
I am also using it with Vue.use(axios) isURLSameOrigin.js?142d:61 Uncaught (in promise) TypeError: Cannot read property ‘protocol’ of undefined when I remove ‘Vue.use(axios)’,it is ok
https://github.com/imcvampire/vue-axios
If you use:
import axios from 'axios';
axios.defaults.baseURL = process.env.BASE_URL;
export default axios;
The error occurs
i solved my own with deleting Vue.use(axios)
I got same problems guys, but I’m not using Vue. It’s happend when I process the
response.data
usingwindow object
, but when I justconsole.log(response.data)
this not show any errors.GuyyyyyyyyyyyyyyyyyyyyyyyyyYYYYYYYYYYYYYYYYYYYYYYYYYYYyyyyyyyyyyyyyyyyyyyyyyyyyyyS
just use this 4 line code and DONE !
import Vue from ‘vue’ import axios from ‘axios’ import VueAxios from ‘vue-axios’ ### this line is important for destroy 😃 ‘protocol’ ERROR ###
Vue.use(VueAxios, axios)
. . . JUST DO THIS !!!
Using Laravel VUE JS, I experienced this same issue. This fixed it for me however -
window.axios = require('axios');
in resources/js/bootstrap.js already scaffolds axios. You wouldn’t need to doVue.use(require('axios'));
in resources/js/app.js. In my own case, this was the issue, so I removed it from app.js.install both of axios and vue-axios
import axios from ‘axios’ import VueAxios from ‘vue-axios’
Vue.use(VueAxios, axios)
that’s worked for me