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.控制臺中也有數(shù)據(jù),但是后端接收為null2.我知道設(shè)置emulateJSON為true的話,已表單的方式提交后端可以接收到參數(shù),但是中文是亂碼的。3.有沒有解決方式,可以正常使用post提交的
問題解答
回答1:根據(jù)你的描述,你后臺能夠接受以x-www-form-urlencoded形式提交的數(shù)據(jù),你的代碼提交的是json數(shù)據(jù),需要修改后臺。
至于x-www-form-urlencoded提交的數(shù)據(jù)中文亂碼的問題,你在headers中設(shè)置一下charset試試
Vue.http.options.headers = { ’Content-Type’: ’application/x-www-form-urlencoded; charset=UTF-8’}
如果還是不行,修改后臺
相關(guān)文章:
1. css - chrome下a標(biāo)簽嵌套img 顯示會多個小箭頭?2. sql語句 - mysql中關(guān)聯(lián)表查詢問題3. python - django models 為生成的html元素添加樣式。4. javascript - 如何將一個div始終固定在某個位置;無論屏幕和分辨率怎么變化;div位置始終不變5. javascript - vscode alt+shift+f 格式化js代碼,通不過eslint的代碼風(fēng)格檢查怎么辦。。。6. javascript - 有什么比較好的網(wǎng)頁版shell前端組件?7. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標(biāo)?8. javascript - iframe 為什么加載網(wǎng)頁的時候滾動條這樣顯示?9. html - vue項目中用到了elementUI問題10. mysql updtae追加數(shù)據(jù)sql語句
