【发布时间】:2018-12-20 01:35:09
【问题描述】:
我在 aurelia 项目中使用 axios 并遵循他们的文档,我已经设置了一个基本的获取请求,如下所示
import Axios from '../../node_modules/axios/index';
export class testService {
constructor() {
this.axios = new Axios({
withCredentials: false,
headers:{
"Accept": "application/json"
},
baseURL: 'http://localhost:3000/'
});
}
test() {
this.axios.get('/items')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
});
}
}
我有一个在“http://localhost:3000/items”上运行的 api 服务器,并在 Chrome 和 Postman 中点击该 url,我可以获得有效的 JSON 响应。但是,运行上面的代码(即调用test() 方法),记录的响应是undefined。
我查看了类似问题的其他答案,但到目前为止,没有一个对我有用。我在这里做错了什么?
【问题讨论】:
标签: ajax rest xmlhttprequest axios aurelia