Simple talk about get, post method in Axios

On the process of learning Vue and NodeJS, it involved AXIOS. Today, in order to test, write GET and POST to interact with the Node server, the result is a long time for Header and parameters, and share it, share

Due to just exposed to AXIOS, in the test method, it is very simple, but the basic function can be achieved, and the gods see it .. Very welcome guide ..

// 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); // The corresponding server acquires the data const urlModule = Require (‘url’); let params = urlmodule.parse (Request.URL, TRUE) .query; // Analysis of data gets the JSON object let value = params.key; // Get parameter value // post method var pararms = new urlsearchparams (); params.append (‘key’, ‘value’); AXIOS.POST (URL , params) .Then (response) {Alert (”. Concat (response.data, ‘\ r \ n’, responsE.STATUS, ‘\ r \ n’, response.statustext, ‘\ r \ n’, response.headers, ‘\ r \ n’, response.config);}); “Function (Error) {Alert (Error);}); // Corresponding server acquisition data const QueryStringModule = Require (‘queryString’); let postdata = ”; Request.on (‘data’, function (chunk) {PostData + = chunk; // Receive data}); let params = queryStringModule.Parse (postData); // parsing data gets json object let value = params.key; // Get parameter value by parameter name
   
This kind of writing speculation should be just a relatively simple implementation, I hope to help others, and I hope the expert advice.

The above simply talks about the GET in AXIOS, the post method is the full content of Xiaobian sharing, I hope to give you a reference, I hope everyone will support Tumi Cloud.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment