Status: 1. pending status, which is initialized and there is no result in the process; 2. fulfilled success status, the resolved status will trigger the subsequent then callback function; 3. rejected failure status, the rejected status will trigger the subsequent then callback function catch callback function.
How to quickly get started with VUE3.0: Enter
the operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
the three states
of the promise object in es61.pending: There is no result in the process
2.resolved: Success
3.rejected: Failure
status changes
1. Pending -> resolved
2. Pending -> rejected
status.
The pending status
Thethen and catch will not be triggered.
The resolved state will trigger the subsequent then callback function.
The rejected state will trigger the subsequent catch callback function.
Then and catch change the state.
Then will return resolved under normal circumstances, and will return rejected if an error is reported.
Catch will return resolved under normal circumstances, and error will be reported. Then return the rejected
test question
//The first question (the result will be printed out 1,3, return to resolved status) Promise.resolve().then(()=>{ console.log(1) //1 resolved }).catch(()=>{ console.log(2) }).then(()=>{ console.log(3) // 3 resolved }) //Second question (the result will be printed out 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 }) //The third question (the result will be printed out 1,2) Promise.resolve.then(()=>{ console.log(1) //1 throw new Error("error1") //rejected }).catch(()=>{ console.log(2) //2 resolved }).catch(()=>{ console.log(3)})