您当前的位置:首页 > 网站建设 > javascript
| php | asp | css | H5 | javascript | Mysql | Dreamweaver | Delphi | 网站维护 | 帝国cms | React | 考试系统 | ajax | jQuery | 小程序 |

vue中get和post请求的区别点总结

51自学网 2022-02-21 13:35:22
  javascript

本教程操作环境:windows7系统、vue2.9.6版,DELL G3电脑。

vue中get和post请求的区别

1、get请求

在GET请求中参数是跟在URL后面,即参数放在header中。能传的参数较小。使用params。

this.$http.get(' URL ').then(result=>{if(result.status===0){// 成功了this.list=result.message;// 这里是假设被请求的数据表中的列表名称为message}else{// 失败了 ,弹出窗体警告alert("数据请求失败");}})

2、post请求

在POST请求中参数是放在body中,并不跟在URL后面。使用data,传递的参数较大。

this.$http.post('URL',{id:this.id},{emulateJSON:true})..then(result=>{if(result.body.status===0){// 成功了}else{// 失败了alert("获取数据失败!");]})

知识点扩展:

vue 使用post/get 下载导出文件操作

<!DOCTYPE html><html>	<head>		<meta charset="UTF-8">		<title>前端项目下载导出文件</title>	</head>	<body>		<script>					/**		 * post 方式 		 * 返回:文件流		 * 好处:可以自己修改文件名称 方便调试		 */	  let params ={      			ListData : this.ListData     		}   	_this.$http.post(url,params,{responseType:"arraybuffer"} //必须添加项    ).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 方式		 * 返回:文件流		 * 好处:前台什么都不需要处理 完全后台处理		 * 缺点:不变调试(需要确保后台接口稳定)		 */		let exportURL = `api/sysLog/export?content=${content}&ip=${ip}`;   	window.open(exportURL, "_blank")				</script>	</body></html>

到此这篇关于vue中get和post请求的区别点总结的文章就介绍到这了,更多相关vue中get和post请求的区别是什么内容请搜索51zixue.net以前的文章或继续浏览下面的相关文章希望大家以后多多支持51zixue.net!


下载地址:
JavaScript实现模态框拖拽效果
JavaScript实现一个简单的圣诞游戏
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。