【发布时间】:2021-02-04 05:42:00
【问题描述】:
目前在一个问题上遇到困难,并没有在网上找到任何可以帮助我的东西。我正在发出一个非常基本的 HTTP 获取请求,以从我制作的 API 中获取 JSON 对象(启用 express+CORS)。
我已尝试使用 Axios 和 VueResource,但遇到相同的问题,我的浏览器显示请求已发出且成功(甚至显示预期数据)。
但我从来没有在承诺中得到任何回报。同时使用 console.logs 和断点显示 .then 和 .catch 函数永远不会运行。
methods: {
getTasks() {
return this.$http.get("http://localhost:3080/api/tasks").then(response => function() {
console.log("in"); // This console.log is never run
this.data = response.data; // this.data is still null
}).catch(err => {
// No errors are returned
console.log(err);
});
}
},
mounted() {
this.getTasks();
}
【问题讨论】:
标签: javascript vue.js http promise get