VUE- access server-side data

VUE- access server-side data

 

1. Installation vue-resource 

npm install vue-resource --save

 

 

After installation, the main.js introduced, as follows:

Import VueResource from  ' view-resource ' ; 

Vue.use (VueResource);  

 

 

get request

 

 
var  the params = { the params : {ID: ID}}
 the this .. $ HTTP GET (URL, the params ) .then (function (RES) {
     // response to a successful callback 
    var Data = res.body;
     // data res.body inside 
}, function (RES) {
     // response error callback 
});

 

 

post request

 
Enable emulateJSON {: to true } after option, the request will be application / x-www-form- urlencoded as Content- type, the same as HTML forms.
var  the params = { the params : {ID: ID}}
 the this . $ http.post (URL, the params , {emulateJSON: to true .}) the then (function (RES) {
     // response to a successful callback 
    var Data = res.body;
     / / data res.body inside 
}, function (RES) {
     // response error callback 
});

 

 

 

JSONP request

 

 
var JSONparams = {
     the params : {ID: ID} 
    JSONP: ' the callback '  // Set the name of a callback parameter, then default is the callback, 
}
  the this $ http.jsonp (URL, JSONparams) .then ((RES. ) => { 
    the console.log (RES); 
}, (ERR) => { 
    the console.log (ERR); 
})

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Quote: https://blog.csdn.net/ant_dreams/article/details/80568420

 

Guess you like

Origin www.cnblogs.com/1285026182YUAN/p/11388075.html