POST 請求,前台有參數,但是后端接受到的為null


問題描述:

POST 請求,前台有參數,但是后端接受到的為null

 

 解決方案:

(1) let info =  new URLSearchParams()  

把參數封裝到info 中  info.append()  加入參數

 const info = new URLSearchParams()
      info.append('uid', this.uid) info.append('part_id', this.part_id) info.append('app_type', 1)
      getNewExerciseList(info).then(res => {
        const data = res.result
        this.result_id = data.result_id
        this.len = data.list.length
        data.list.forEach(element => {
          if (element.type === 1 || element.type === '1') {
            element.radio = ''
          } else if (element.type === 2 || element.type === '2') {
            element.checkList = []
          }
        })
}

  (2)引入QS

 

 

  sbt(){
        let data = {
         'username': 'ddd',
         'password': '101010'
        }
         
                  this.axios({
                            method: "post",
                            url: '/api/PsychoSys/regedit.action',
                            data: Qs.stringify(data)
                        })
                        .then(function(res) {
                           console.log(res);
                       })
                        .catch(function(err) {
                           console.log(err);
                       });
 
      },

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM