先上一段響應攔截的代碼
service.interceptors.response.use( response => { ... }, error => { console.log(error) } )
此處在打印error時發現error沒有status, message等屬性,如下

但是在請求響應中是能看到返回的結構的,如下

結論:此處需要獲得響應體需要使用error.response,結構如下

如果需要使用message則需要取error.response.data.message
先上一段響應攔截的代碼
service.interceptors.response.use( response => { ... }, error => { console.log(error) } )
此處在打印error時發現error沒有status, message等屬性,如下

但是在請求響應中是能看到返回的結構的,如下

結論:此處需要獲得響應體需要使用error.response,結構如下

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