Learning Vue and Nodejs process, involving the Axios, today in order to test, wrote Get and post two methods to interact with node server, the result because the header and parameters for a long time, in this record, while sharing;
Because of the new contact Axios, in the test method, writing is very simple things, but can achieve the basic function, the great god see words. Guidance is very welcome.
Get method
Axios.get (URL, {
Params: {' key ': ' Value '}
}). Then (function (response) {
Alert ('. Concat (Response.data, ' \ r \ n ', Response.Status, ' \ r \ n ', Response.statustext, ' \ r \ n ', response.headers, ' \ r \ n ' , Response.config));
}). catch (function (error) {
alert (error);
});
Get data on the server side
Const Urlmodule = require (' URL ');Let params = Urlmodule.parse (Request.url, true). Query; //Parse data to get JSON object Let value = Params.key; //Get parameter values by parameter name
Post method
var params = new Urlsearchparams ();
Params.append (' key ', ' value ');
Axios.post (URL, params). Then ( Function (response) {
alert (' . Concat (Response.data, ' \ r \ n ', Response.Status, ' \ r \ n ', Response.statustext, ' \ r \ n ', response.headers, ' \ r \ n ', Response.config));
}). catch (function (error) {
alert (error);
});
Get data on the server side
Const Querystringmodule = require (' querystring ');Let postdata = ";request.on (' Data ', function (chunk) {PostData + = chunk; //Receive data });Let params = Querystringmodule.parse (postdata); //Parse data to get JSON object Let value = Params.key; //Get parameter values by parameter name
This kind of writing speculation should be just a relatively simple implementation, hoping to help others, but also hope that master advice;
The Get,post method of Axios