当前位置:首页 > 开发教程 > js/jQuery教程 >

Vue使用Post进行表单提交

时间:2022-06-01 13:33 来源:未知 作者:距离产生距离 收藏

这篇文章主要介绍了Vue使用Post进行表单提交,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

使用Post进行表单提交

下面就是使用Vue提交表单的方法

Vue使用Post进行表单提交

submitForm(event) {
					event.preventDefault();
					let formData = new FormData();
					formData.append('id', this.param.id);
					formData.append('categoryName', this.param.namee);
					formData.append('description', this.param.descrip);
					var url ="";
					if(this.isSave){
						url = "http://localhost:8080/bookStore/category.doflag=add"
					}else{
						url = "http://localhost:8080/bookStore/category.doflag=update&id="+this.param.id
					}
					this.$http.post(url, formData).then(function (res) {
					  if (res.status === 200) {
						  this.isShowModal=false;
						  var title = this.isSave"添加成功!":"修改成功!";
						  swal({title:title,text:"",type:"success"});
						  this.queryData();
						  this.clearData();
					  }
					})
				}

vue中使用Post问题

get的使用

this.$axios.get("/api/Main/InputValue",{
  params:{ //传参
    json:"123"
  }
})
.then(function(res){
  //console.log(res)     
})
.catch(function(err){
   console.log("请求失败233");
});

post的使用

this.$axios.post("/api/Main/posttest",{json:"123"})//传参
.then(function(res){
   console.log(res)     
})
.catch(function(err){
   console.log("请求失败233");
});

post和get传参数的方式是不一样的,写post的时候如果在params里面传参数,后台是收不到的~~~~

以上为个人经验,希望能给大家一个参考,也希望大家多多支持源码搜藏网。


下一篇:没有了

js/jQuery教程阅读排行

最新文章