-
1.报错
{status: 500, success: false,…}
data: null
msg: "JSON parse error: Cannot deserialize instance ofjava.util.ArrayList
out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance ofjava.util.ArrayList
out of VALUE_STRING token? at [Source: (PushbackInputStream); line: 1, column: 8] (through reference chain: co.yixiang.modules.cart.param.CartIdsParm["ids"])"
status: 500
success: false
time: "2020-12-02 11:28:41"
这里是数据格式的问题,后端要求的是数组,我给传了字符串 -
2 报错
此处在axios请求时,应将
headers: { Authorization: window.sessionStorage.getItem("token") },
改为
headers: { Authorization: window.sessionStorage.getItem("token"), 'Content-Type': 'application/json' }
-
3.报错代码(methods)
del() { this.$axios({ method: "get", url: "http://192/api/cart/list", headers: { Authorization: window.sessionStorage.getItem("token") } }) .then(res => { const selectLists = this.selected console.log(selectLists) let selectList = {} for (let i = 0; i < selectLists.length; i++) { selectList = selectLists[i] const selectedid = { id: selectList.id } this.selectedid.push(selectedid.id) const selectedes = this.selectedid.join(',') console.log(selectedes) } this.selectedid = this.selectedid.toString() // 这里是将数组转变为字符串 this.$axios({ method: "post", url: "http://192/api/cart/del", headers: { Authorization: window.sessionStorage.getItem("token")}, data: { ids: this.selectedid } }) .then(res => { console.log(res) }) .catch(function(error) { console.log(error) }) console.log(this.selectedid) }) .catch(function(error) { console.log(error) })
}
-
正确的代码
del() { this.$axios({ method: "get", url: "http://19200/api/cart/list", headers: { Authorization: window.sessionStorage.getItem("token") } }) .then(res => { const selectLists = this.selected console.log(selectLists) let selectList = {} for (let i = 0; i < selectLists.length; i++) { selectList = selectLists[i] const selectedid = { id: selectList.id } this.selectedid.push(selectedid.id) const selectedes = this.selectedid.join(',') console.log(selectedes) } this.$axios({ method: "post", url: "http://192/api/cart/del", headers: { Authorization: window.sessionStorage.getItem("token"), 'Content-Type': 'application/json' }, data: JSON.stringify({ ids: this.selectedid }) }) .then(res => { console.log(res) }) .catch(function(error) { console.log(error) }) console.log(this.selectedid) }) .catch(function(error) { console.log(error) })
}