当前位置: 首页>后端>正文

quasar连接后台报错

  • 1.报错
    {status: 500, success: false,…}
    data: null
    msg: "JSON parse error: Cannot deserialize instance of java.util.ArrayList out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.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"

    quasar连接后台报错,第1张
    2.png

    这里是数据格式的问题,后端要求的是数组,我给传了字符串
  • 2 报错


    quasar连接后台报错,第2张
    3.png

    此处在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)
      })
    

    }


https://www.xamrdz.com/backend/39f1994108.html

相关文章: