gpt4 book ai didi

javascript - 在 ionic cordova build android 上出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:41:03 24 4
gpt4 key购买 nike

刚开始学习 ionic 3。在 ionic cordova build android 上出现以下错误

(node:6364) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]
(node:6364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

以下是我的 ionic 信息。

cli packages: (C:\Users\HIT\AppData\Roaming\npm\node_modules)

@ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
global packages:

cordova (Cordova CLI) : 8.0.0
local packages:

@ionic/app-scripts : 3.1.6
Cordova Platforms : none
Ionic Framework : ionic-angular 3.9.2
System:

Node : v8.5.0
npm : 5.3.0
OS : Windows 10
Environment Variables:

ANDROID_HOME : D:\AndroidSdk\platform-tools
Misc:

backend : pro

我在下面写了 promise 代码

 postData(credentials, type) {
return new Promise((resolve, reject) => {
let headers = new Headers();

this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
});
}

我在下面调用了postData函数

signup(){
//Api connection
this.authService.postData(this.userData , "register.php").then((result) => {
this.reposeData = result;
console.log(this.reposeData);
localStorage.setItem('userData' , JSON.stringify(this.reposeData))
this.navCtrl.push(TabsPage);
}, (err) => {
//connection failed
});

这是我的代码问题吗?

最佳答案

根据错误消息,您尚未处理对您的 Promise 对象之一的拒绝。每个 promise 都应该有一个 .catch(...)。

var flag = false;
var Test = function () {
return new Promise(function (resolve, reject) {
if (flag === true)
resolve();
else
reject();
});
}
var testFunc = Test();
testFunc.then(function () {
alert("Promise Resolved");
});
testFunc.catch(function () {
alert("Promise Rejected");
});

阅读有关 Promise 对象的更多信息 here

关于javascript - 在 ionic cordova build android 上出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48145380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com