vue-resource 返回一个 PromiseObj
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());
});
Promise 结果值应该使用 then
方法使用:
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);
})
如何访问 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());
});
Promise 结果值应该使用 then
方法使用:
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);
})