0

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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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)
1

Yes, as a separate file that you call from your page: https://github.com/pagekit/vue-resource

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.