如果得到这样的响应 - data:Array(0)length:0
如何处理错误以及如何在vuejs中找到没有匹配数据的消息。
首先,如果使用async / await,您应该使用try / catch包装axios请求,或者只使用then..catch方法。
这是一个简单的例子
axios.get('http://api.com')
.then((response) => {
if (response.data.length === 0) { // Lets check if response contains any items
// Do Your 'no items found' logic here
console.log('No items found')
return
} else { // We have items, handle them here!
// We have some items, lets log them
console.log(response.data)
}
})
.catch((error) => {
// Catch and handle any errors here
console.log(error)
})