[英]vue-resource returning a PromiseObj
如何在Ajax調用中訪問響應數據? 如果我記錄response.text()
則會顯示PromiseObj
。
安慰
PromiseObj
context: undefined
promise: Promise {status: "resolved", result: ")]}',↵{\"Result\":\"SUCCESS\",\"Data\":{\"mode\":\"DEV\"}}"}
碼
this.$http.post(endpoint, data, []).then((response) => {
console.log(response.status);
console.log(response.text());
}, (response) => {
console.log(response.status);
console.log(response.json());
});
應使用then
方法消耗Promise結果值:
response.text().then(console.log)
您可以通過返回承諾並鏈接到其上來簡化代碼:
this.$http.post(endpoint, data, []).then(response => {
console.log(response.status);
return response.text();
}, response => {
console.log(response.status);
return response.json();
}).then(result => {
console.log(result);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.