Promise’s basic usage

 // Promise object, can save state 

//Promise first step
// Asynchronous code is written in the Promise function Step 2
const promise = new Promise((resolv, reject) => {
// Promise has three states: pending fulfilled rejected span>
// In progress Has succeeded Has failed
// Get system information
wx.getSystemInfo({
success: res
=> resolv(res),
fail: error
=> reject(error)
})
})

// Step 3: Call the promise, you can call two callbacks Function, the first one is successful, the second one is failed
promise.then(
res
=>console.log(res),
error
=>console.log(error)
)

 // Promise object, can save state

//Promise first step
// Asynchronous code is written in the Promise function Step 2
const promise = new Promise((resolv, reject) => {
// Promise has three states: pending fulfilled rejected span>
// In progress Has succeeded Has failed
// Get system information
wx.getSystemInfo({
success: res
=> resolv(res),
fail: error
=> reject(error)
})
})

// Step 3: Call the promise, you can call two callbacks Function, the first one is successful, the second one is failed
promise.then(
res
=>console.log(res),
error
=>console.log(error)
)

Leave a Comment

Your email address will not be published.