I know that Vuejs can be more effective than jQuery for DOM manipulation and user interactions handling. What about remote asynchronous HTTP (Ajax) calls? I'm searching for a Vue.js core API to do this.
Asked
Active
Viewed 1,070 times
2 Answers
1
Yes, as a separate file that you call from your page: https://github.com/pagekit/vue-resource

Nelson Rodriguez
- 492
- 3
- 12
1
I am using axios as HTTP client for making api calls, I have created a gateways
folder in my src
folder and I have put files for each backend, creating axios instances, like following
myApi.js
import axios from 'axios'
export default axios.create({
baseURL: 'http://localhost:3000/api/v1',
timeout: 5000,
headers: {
'X-Auth-Token': 'f2b6637ddf355a476918940289c0be016a4fe99e3b69c83d',
'Content-Type': 'application/json'
}
})
You can look at detailed answer related to this here and here.
-
Just notice that vue-resource automatically makes 'this' the reference to the calling component/Vue instance. This is not the case with 'axios' (because it's a general purpose library) and so you must declare something like `var self=this;` before the call and reference `self` inside your promise (or use `bind`) – Nelson Rodriguez Jun 02 '17 at 15:59