Solve the Vue AXIOS POST request, the background acquisition of data is not available

Recently, I need to use VUE. The background is PHP. I used AXIOS for the first time. I thought as Ajax, it would be very simple, but the result is often unsatisfactory, GET request is very simple, here Do not say, mainly say the POST request method.

Using AXIOS for POST request, the background actually does not receive the data, which is wondering, so online search, now the solution used will be said to everyone:

1.New UrlsearchParams Mode

The way of using params.Append (“Property Name: Property Value) is not problematic, and the background can receive data normally, but I Discover a problem, don’t know if you have encountered, when you pass the data contains an array, you will find that the form of the string is the form of strings from the string, and non-normal formats Arr: [A1, B1 , c1] does not meet my requirements, continue to find.

2.Qs.stringify way

see a lot of online solutions are saying qs, qs then installed plug-ins, use the method is simple. First install the plugin, then register the component, AXIOS.POST (URL, QS.Stringify (params)) The data received under the background output, there is a value, don’t mention how happy it, just happy is not two minutes, wait another look, this is found that when the data is empty, QS actually gives it off, straight No pass, this is a sad. . .

3. Change the rear reception method

Most of the online posts are treated at the front end, but there is nothing a good solution, so I turn my thoughts to the background. Changing the receiving method of the background,

finally solved using file_get_contents (‘php: // input’). The above solves the Vue AxiosPOST request, the future problem method for obtaining data is the total content of Xiaobian sharing to everyone, 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