Vue使用Post進行表單提交
更新時間:2022年06月01日 11:10:40 作者:海濤高軟
這篇文章主要介紹了Vue使用Post進行表單提交,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
使用Post進行表單提交
下面就是使用Vue提交表單的方法
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.do?flag=add" }else{ url = "http://localhost:8080/bookStore/category.do?flag=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傳參數(shù)的方式是不一樣的,寫post的時候如果在params里面?zhèn)鲄?shù),后臺是收不到的~~~~
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue element實現(xiàn)表格增加刪除修改數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了vue element實現(xiàn)表格增加刪除修改數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-05-05VUE安裝依賴時報錯:npm ERR! code ERESOLVE的解決
在使用npm安裝項目依賴時,有時會遇到錯誤信息 “npm ERR! code ERESOLVE”,本文就來介紹一下VUE安裝依賴時報錯的解決,具有一定的參考價值,感興趣的可以了解一下2023-10-10vue+axios實現(xiàn)文件下載及vue中使用axios的實例
這篇文章主要介紹了vue+axios實現(xiàn)文件下載及vue中使用axios的實例,需要的朋友可以參考下2018-09-09vue .then和鏈?zhǔn)秸{(diào)用操作方法
這篇文章主要介紹了vue .then和鏈?zhǔn)秸{(diào)用操作方法,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07