These days in the use of Vue Axios send GET request is very handy, but when sending a POST request is always in the successful callback function inside the return parameter does not exist, then wondered, after looking at the data, finally got the solution, here to do a summary:
First of all, we use the NPM install Axios will be installed by default QS, so we have to introduce QS into the Axios, and then need to instantiate a new Axios, and set his message header for ' Content-type ': ' Application /x-www-form-urlencoded '
1Let QS = require ('QS'); 2Let instance =Axios. Create ({3Headers: {'Content-type':'application/x-www-form-urlencoded' }4 });5Let data =qs.stringify ({6 "user_id": This. user_id,7 "Cate_name": This. Catename8 });9Instance.post ("./frontend/web/cate/create", data)Ten. Then (res = { One if(Res.status = = $) { AAlert"Add success! ") - This. Inittabledata (); - } the }) -.Catch(Err = { - Console.log (err); -});
This solves the problem of using Axios to send post requests in Vue.
Use Axios to send post requests in Vue