Operating environment of this tutorial: Windows 7 system, vue 2.9.6 version, DELL G3 computer.
Difference between get and post requests in vue
1. Get request
In the GET request, the parameters are followed by the URL, that is, the parameters are placed in the header. The parameters that can be passed are smaller. Use params.
this.$(' URL ').then(result=>{ if(===0){ // Success=; // Here is a suppose that the list name in the requested data table is message}else{ // Failed, pop-up form warningalert("Data request failed"); } })
2. Post request
In the POST request, the parameters are placed in the body and are not followed by the URL. Using data, the parameters passed are larger.
this.$('URL',{id:},{emulateJSON:true})..then(result=>{ if(===0){ // Success}else{ // Failedalert("Failed to obtain data!"); ] })
Knowledge point expansion:
vue use post/get to download and export file operation
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Front-end project download export file</title> </head> <body> <script> /** * post method * Return: File Stream * Benefits: You can modify the file name yourself for easy debugging */ let params ={ ListData : } _this.$(url,params,{responseType:"arraybuffer"} //Items must be added ).then(function(res) { (res) var blob = new Blob([], {type: 'application/msword;charset=utf-8'}); var filename = ""; var a = ('a'); var url = (blob); = url; = filename; var body = ('body')[0]; (a); (); (a); (url); } /** * get method * Return: File Stream * Benefits: Nothing is required in the front desk, and complete background processing * Disadvantages: Unchanged debugging (need to ensure the stability of the background interface) */ let exportURL = `api/sysLog/export?content=${content}&ip=${ip}`; (exportURL, "_blank") </script> </body> </html>
This is the end of this article about the difference between get and post requests in vue. This is the end of this article. For more information about the differences between get and post requests in vue, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!