java - vue-resourse的post請求前端向后端傳值 后端接收null
問題描述
let adrObj = { ’consignee’: this.contact, ’address’: this.detailAdress, ’province’: this.addArr[0], ’city’: this.addArr[1], ’area’: this.addArr[2], ’isDefault’: this.isDefult === true ? ’1’ : ’0’, ’consigneePhone’: ’0’ + this.phoneNum, ’id’: id, ’customerCode’: this.CUSTOMERCODE}this.$http.post(’/api/receivingAddress/editMyAddress’, adrObj).then((res) => { console.log(’success’, res)}, (res) => { console.log(’error’, res.data)})
問題描述,通過這種方式向后端傳參,后端接收到的都是null
1.控制臺中也有數據,但是后端接收為null2.我知道設置emulateJSON為true的話,已表單的方式提交后端可以接收到參數,但是中文是亂碼的。3.有沒有解決方式,可以正常使用post提交的
問題解答
回答1:根據你的描述,你后臺能夠接受以x-www-form-urlencoded形式提交的數據,你的代碼提交的是json數據,需要修改后臺。
至于x-www-form-urlencoded提交的數據中文亂碼的問題,你在headers中設置一下charset試試
Vue.http.options.headers = { ’Content-Type’: ’application/x-www-form-urlencoded; charset=UTF-8’}
如果還是不行,修改后臺
相關文章:
1. javascript - vue2如何獲取v-model變量名2. javascript - 求幫助 , ATOM不顯示界面!!!!3. html5 - HTML代碼中的文字亂碼是怎么回事?4. javascript - vue2.0中,$refs對象為什么用駝峰的方式獲取不到屬性?5. python bottle跑起來以后,定時執行的任務為什么每次都重復(多)執行一次?6. 解決Android webview設置cookie和cookie丟失的問題7. javascript - nodejs使用mongoose連接數據庫,使用post提交表單在后臺,后臺處理后調用res.redirect()跳轉界面無效?8. javascript - 能否讓vue-cli的express修改express重啟服務9. python - 爬蟲模擬登錄后,爬取csdn后臺文章列表遇到的問題10. html5 - 急求?被公司問住了
