By adding this configuration VueResource provides us a global $http object, which helps us to make http requests anywhere from our Vue app. Making GET request For learning purposes, we are using json placeholder API for making http requests. GET request method is used to fetch the data from the backend API, let's see an example. App.vue MIT license vue-resource The plugin for Vue.js provides services for making web requests and handle responses using a XMLHttpRequest or JSONP. Features Supports the Promise API and URI Templates Supports interceptors for request and response Supports latest Firefox, Chrome, Safari, Opera and IE9+ Supports Vue 1.0 & Vue 2.0
Vueresource 工具栈
11 I have a number of post requests in my app. Some of them have to have and extrace header with token I'm not sure how to append it So far my code is like this. I'm checking if there is a token and when append it to headers and after that I make post request with vue-resource post method. Installation You can install it via yarn or NPM. $ yarn add vue-resource $ npm install vue-resource CDN Available on jsdelivr, unpkg or cdnjs. Example This sends an HTTP POST request to the Test JSON API which is a fake online REST API that includes a /products route that responds to POST requests with the contents of the post body plus a new id property and createdAt date property. If a request is sent using
this.$http
or
this.$resource
the current Vue instance is available as
this
in a interceptor callback.\n