Javascript 浏览器显示已发出get请求,但承诺中未返回任何内容?

Javascript 浏览器显示已发出get请求,但承诺中未返回任何内容?,javascript,vue.js,http,promise,get,Javascript,Vue.js,Http,Promise,Get,目前在一个问题上遇到了难题,在网上找不到任何帮助。我正在发出一个非常基本的HTTP get请求,以从我制作的API(启用了express+CORS)中获取JSON对象 我尝试使用Axios和VueResource,但遇到了相同的问题,我的浏览器显示请求已发出且成功(甚至显示预期数据) 但我从来没有得到任何回报的承诺。并使用console.logs和断点显示.then和.catch函数永远不会运行 方法:{ getTasks(){ 返回此。$http.get(“http://localhost:

目前在一个问题上遇到了难题,在网上找不到任何帮助。我正在发出一个非常基本的HTTP get请求,以从我制作的API(启用了express+CORS)中获取JSON对象

我尝试使用Axios和VueResource,但遇到了相同的问题,我的浏览器显示请求已发出且成功(甚至显示预期数据)

但我从来没有得到任何回报的承诺。并使用console.logs和断点显示.then和.catch函数永远不会运行

方法:{
getTasks(){
返回此。$http.get(“http://localhost:3080/api/tasks)然后(响应=>function(){
console.log(“in”);//此console.log永远不会运行
this.data=response.data;//this.data仍然为空
}).catch(错误=>{
//不会返回任何错误
控制台日志(err);
});
}
},
安装的(){
this.getTasks();
}

箭头函数的正确语法为:

 (params) => {
  // code
 }
将您的
然后
回调更改为:

 getTasks() {
      return this.$http.get("http://localhost:3080/api/tasks").then(response => {
        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);
      });
    }