[英]Browser shows get request is made but nothing is returned in promise?
目前在一個問題上遇到困難,並沒有在網上找到任何可以幫助我的東西。 我正在制作一個非常基本的 HTTP 獲取請求,以從啟用 ZDB974238714CA38DE634CORA7ACED14 的 ZDB974238714CA8DE63ZCORA7C14
我已經嘗試過 Axios 和 VueResource 但有同樣的問題,我的瀏覽器顯示請求已發出並且成功(甚至顯示了預期的數據)。
但我從未在 promise 中獲得任何回報。 並同時使用 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();
}
箭頭函數的正確語法是:
(params) => {
// code
}
將您的then
回調更改為:
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);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.