[英]Vue.js - How to determine if an axios request has no response data
I am trying to test if the IP address provided by a user is the expected IP, so i send a request to that IP address which is expected to be running the API service, if the IP is correct it return success but if the IP is錯誤它沒有返回響應數據,在應用程序的前端是 Vue.js 我希望能夠知道發生了什么並向用戶發出警報,如果它成功我能夠做到這一點,但如果它不是什么都沒有發生了,我如何得到那個錯誤信息?
這是我的代碼
PublisherUrl().get('/api/publish-lv/').then(()=>{
Toast.fire({
icon: 'success',
title: 'Publisher Connected Successfully'
})
}).catch((error)=>{
console.log(error)
Toast.fire({
icon: 'error',
title: 'Publisher Device Unreachable'
})
})
}
里面的回調 function then
有一個參數響應,返回數據,標題和狀態......
PublisherUrl().get('/api/publish-lv/').then((response)=>{
if(response.data.length===0){
Toast.fire({
icon: 'info',
title: 'No data'
})
}else{
Toast.fire({
icon: 'success',
title: 'Publisher Connected Successfully'
})
}
}).catch((error)=>{
console.log(error)
Toast.fire({
icon: 'error',
title: 'Publisher Device Unreachable'
})
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.