Ajax calls in Vue applications


Why Ajax?

Unless you're doing SSR (Server Side Rendering) in your Vue application, you're going to need a way to fetch data from your servers. Ajax calls are perfect to accomplish this. 


Which Ajax package?

When it comes to ajax calls, it doesn't matter which JavaScript framework you are using, you can choose from many ajax packages on the Internet. You can even go with pure JavaScript ajax code (not recommended at all!). 

But the recommended ajax package for Vue applications is Axios


Already using Vue Resource?

Vue Resource used to be the previous recommended ajax package for Vue apps. In case you're already using it on a project, there's no urge on moving to Axios. But if you're starting a new one, I suggest moving. 

By any chance, if you're still willing to migrate to Axios below code would help you a lot:

Vue.prototype.$http = axios;

By using it, you don't have to change this.$http to axios in all your ajax calls (god knows how many!).


Which backend language/framework?

The truth is you can use any backend language/framework you desire as long as you can send JSON responses with it. 


Comments: