【vue开发】new Promise用法的简单示例教程
initLicenseMax () {
const val = new Promise((resolve, reject) => {
if (this.licenseIndexId) {
DocLicenseControllerService.getLicenseMaxIdUsingGet({
licenseId: this.licenseId,
licenseIndexId: String(this.licenseIndexId),
licenseYear: Number(this.year)
}).then(data => {
this.maxLicense = data as any
resolve('{label:成功了在then中传递参数继续执行}')
})
} else {
reject('失败了,在catch中抛出错误')
}
})
console.log(val,'val-==')
return val
}
// 开始调用
this.initLicenseMax().then((res: any) => {
console.log(res, 'res-1') // {label:成功了在then中传递参数继续执行} res-1
}).catch((err: any) => {
console.log(err, 'err--2') // 失败了,在catch中抛出错误 err--2
})
all 哪个执行的最慢 哪个回调
race 哪个执行的最快 哪个回调
更多用法可以参考这个,传送门:https://www.cnblogs.com/mg6666/p/14508322.html
本文来自博客园,作者:JeckHui;
个人主页:前端实用站点推荐; 热榜资讯早读:热榜资讯-导航;
转载请注明原文链接:https://www.cnblogs.com/xiaohuizhang/p/17197839.html

浙公网安备 33010602011771号