大家好,又见面了,我是你们的朋友全栈君。
cc = (resolve, reject) => {
const timeOut = 5
setTimeout(function () {
if (timeOut < 1) {
console.log('call resolve()...');
resolve('200 OK');
}
else {
console.log('call reject()...');
reject('timeout in ' + timeOut + ' seconds.');
}
}, timeOut * 1000);
}
clickFunction = () => {
new Promise(this.cc).then(data => {
alert(data)
}).catch(function (reason) {
console.log('Failed: ' + reason);
});
}
<button onClick={this.test}>a</button>
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/150521.html原文链接:https://javaforall.net
