es6中promise对象的状态有哪些
作者:互联网
2022-09-13
状态:1、pending进行中的状态,该状态进行初始化,在过程中还没有结果;2、fulfilled成功状态,resolved状态会触发后续的then回调函数;3、rejected失败状态,rejected状态会触发后续的catch回调函数。

如何快速入门VUE3.0:进入学习
本教程操作环境:windows10系统、ECMAScript 6.0版、Dell G3电脑。
es6中promise对象的状态有哪些
三种状态
1.pending:在过程中还没有结果
2.resolved:成功
3.rejected:失败
状态变化
1、pending -> resolved
2、pending -> rejected
状态的表现
pending状态不会触发then和catch
resolved状态会触发后续的then回调函数
rejected状态会触发后续的catch回调函数
then和catch改变状态
then正常情况下会返回resolved,报错则返回rejected
catch正常情况下会返回resolved,报错则返回rejected
测试题
//第一题(结果会打印出来1,3,返回resolved状态)
Promise.resolve().then(()=>{
console.log(1) //1 resolved
}).catch(()=>{
console.log(2)
}).then(()=>{
console.log(3) // 3 resolved
})
//第二题(结果会打印出来1,2,3)
Promise.resolve().then(()=>{
console.log(1) //1
throw new Error("error1") //rejected
}).catch(()=>{
console.log(2) //2 resolved
}).then(()=>{
console.log(3) //3 resolved
})
//第三题(结果会打印出来1,2)
Promise.resolve.then(()=>{
console.log(1) //1
throw new Error("error1") //rejected
}).catch(()=>{
console.log(2) //2 resolved
}).catch(()=>{
console.log(3)})
相关标签:
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
Vue 项目结构与命名规范
Vue组合式API响应式状态声明:ref与reactive实战解析
Vue3+Pinia实战完整版|从入门到精通,替代Vuex的状态管理首选
Element / AntD 官方都没做好的功能,被这个开源小插件搞定了!
目录:VTJ.PRO 在线应用开发平台技术揭秘
4.响应式系统基础:从发布订阅模式的角度理解 Vue3 的数据响应式原理
vue3中静态提升和patchflag实现
你的 Vue 3 ref(),VuReact 会编译成什么样的 React?
你的 Vue 3 reactive(),VuReact 会编译成什么样的 React?
Vue3 转 React:组件透传 Attributes 与 useAttrs 使用详解|VuReact 实战
AI精选
