使用promise的then方法获取Axios返回的结果。
示例代码:
axios.get('/api/data')
.then(function (response) {
console.log(response.data);
// 在这里处理返回的数据
})
.catch(function (error) {
console.log(error);
});
在这个示例中,我们向/api/data发送一个get请求,并用.then()处理响应,如果有错误则用.catch()处理。在.then()代码块中,我们可以像操作js对象一样访问响应数据,例如response.data。