Summary of the differences between get and post requests in Vue

Summary of the differences between get and post requests in Vue

The operating environment of this tutorial: Windows 7 system, vue 2.9.6 version, DELL G3 computer.

The difference between get and post requests in Vue

1. Get request

In a GET request, the parameters follow the URL, that is, the parameters are placed in the header. The parameters that can be transmitted are relatively small. Use params.

this.$http.get(' URL ').then(result=>{
if(result.status===0){
// Success this.list=result.message;
// Here it is assumed that the name of the list in the requested data table is message
}else{
// Failed, pop-up window alert alert("Data request failed");
}
})

2. Post request

In a POST request, the parameters are placed in the body and not following the URL. When using data, the parameter passed is larger.

this.$http.post('URL',{id:this.id},{emulateJSON:true})..then(result=>{
if(result.body.status===0){
// Success }else{
// Failed alert("Failed to obtain data!");
]
})

Knowledge point expansion:

Vue uses post/get to download and export file operations

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Front-end project download export file</title>
	</head>
	<body>
		<script>
			
		/**
		 * post method * Return: file stream * Advantage: you can modify the file name yourself for easy debugging */
	  let params = {      
			ListData : this.ListData     
		}
   	_this.$http.post(url,params,{responseType:"arraybuffer"} //Must add items).then(function(res) {
      console.log(res)
      var blob = new Blob([res.data], {type: 'application/msword; charset=utf-8'});
      var filename = "download.doc";
      var a = document.createElement('a');
      var url = window.URL.createObjectURL(blob);
      a.href = url;
      a.download = filename;
      var body = document.getElementsByTagName('body')[0];
      body.appendChild(a);
      a.click();
      body.removeChild(a);
      window.URL.revokeObjectURL(url);
		}
		
		/**
		 * get method * Return: file stream * Advantages: nothing needs to be processed in the foreground, all processing is done in the background * Disadvantages: unchanged debugging (need to ensure the stability of the background interface)
		 */
		let exportURL = `api/sysLog/export?content=${content}&ip=${ip}`;
   	window.open(exportURL, "_blank")
		
		</script>
	</body>
</html>

This concludes this article about the differences between get and post requests in vue. For more information about the differences between get and post requests in vue, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solve the cross-domain problem of get and post requests of vue $http
  • Vue uses post/get to download and export file operations
  • Vue basics: using get, post, and jsonp to implement interactive functions
  • Vue axios global interception get request, post request, configuration request example code
  • Vue axios data request get, post method and example detailed explanation
  • Vuejs uses axios asynchronous access to use get and post examples

<<:  40 fonts recommended for famous website logos

>>:  Comprehensive summary of mysql functions

Recommend

Summary of Linux ps and pstree command knowledge points

The ps command in Linux is the abbreviation of Pr...

Linux file systems explained: ext4 and beyond

Today I will take you through the history of ext4...

Practical record of MySQL 5.6 master-slave error reporting

1. Problem symptoms Version: MySQL 5.6, using the...

Summary of 16 XHTML1.0 and HTML Compatibility Guidelines

1. Avoid declaring the page as XML type . The pag...

vue-table implements adding and deleting

This article example shares the specific code for...

The image element img has extra blank space in IE6

When doing DIV+CSS layout of the page, it is very...

A brief analysis of the count tracking of a request in nginx

First, let me explain the application method. The...

Commands to find domain IP address in Linux terminal (five methods)

This tutorial explains how to verify the IP addre...

Implementation of react routing guard (routing interception)

React is different from Vue. It implements route ...

Linux service monitoring and operation and maintenance

Table of contents 1. Install the psutil package S...

JavaScript type detection method example tutorial

Preface JavaScript is one of the widely used lang...

Detailed explanation of CSS BEM writing standards

BEM is a component-based approach to web developm...

Four data type judgment methods in JS

Table of contents 1. typeof 2. instanceof 3. Cons...

KVM virtualization installation, deployment and management tutorial

Table of contents 1.kvm deployment 1.1 kvm instal...