Skip to content
Advertisement

axios is not defined in vue js cli

I installed axios using the npm install axios command this is my package.json dependencies

JavaScript

I registered the axios in my main.js file.

JavaScript

When I tried to use axios in one of my components I get this error:

JavaScript

How to fix this?

Advertisement

Answer

Vue.use means adding plugins. However, axios is not a plugin for Vue, so you can not add it globally via use.

My recommendation is importing axios only when you need it. But if you really need to access it globally, you may like to add it to prototype.

JavaScript

Then you can access axios in vue using this.$axios

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement