鍍金池/ 問(wèn)答/HTML5  HTML/ axios請(qǐng)求get方法請(qǐng)求數(shù)據(jù)跳錯(cuò)誤

axios請(qǐng)求get方法請(qǐng)求數(shù)據(jù)跳錯(cuò)誤

問(wèn)題描述

axios請(qǐng)求數(shù)據(jù)時(shí),直接catch錯(cuò)誤響應(yīng),不讀axios.get().then()方法中的response,而是直接跳到catch中的err,并且打印出錯(cuò)誤信息

問(wèn)題出現(xiàn)的環(huán)境背景及自己嘗試過(guò)哪些方法

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

axios.get('/api/ac/app.json').then(response => {

          if(response && response.status === 200) {
            console.log('******')
            if(response.data.errcode === 0){
              try{
                this.result = response.data.data;
              } catch (err) {
                throw new Error('數(shù)據(jù)錯(cuò)誤')
              }
            }
          } else {
            this.$alert('接口的數(shù)據(jù)沒(méi)有正確響應(yīng)','請(qǐng)求接口有誤',{
              confirmButtonText: '確定',
              callback: action => {
                this.$message({
                  type: 'info',
                  message: '檢查代碼'
                });
              }
            })
          }
        }).catch(err => {
          console.log(err)
        });

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

期待的是response響應(yīng)返回的json數(shù)據(jù)
實(shí)際看到的是

Error: Request failed with status code 404

at createErrorResponse (utils.js?98cb:117)
at Object.settle (utils.js?98cb:97)
at handleRequest (handle_request.js?fff0:73)
at eval (index.js?3efb:18)
at new Promise (<anonymous>)
at MockAdapter.eval (index.js?3efb:17)
at dispatchRequest (dispatchRequest.js?5c70:52)
回答
編輯回答
柒喵

接口404了 首先確認(rèn)你這接口是否存在

2017年5月31日 03:13
編輯回答
孤酒

接口有問(wèn)題吧

2018年4月3日 16:00