// Promise写法一
new Promise ( (resolve,reject) => {
resolve('aaaa')
}).then((res) => {
console.log(res)
return new Promise((resolve, reject) => {
resolve('bbbb')
})
}).then((res) => {
console.log(res)
})
// Promise写法二
new Promise ( (resolve,reject) => {
resolve('cccccc')
}).then((res) => {
console.log(res)
return Promise.resolve(res+'22')
}).then((res) => {
console.log(res)
})
// promis的all写法 多次请求接口 需要先后顺序时候
Promise.all([
new Promise ((resolve,reject) => {
resolve({a:'1',b:'2'})
}),
new Promise ((resolve,reject) => {
resolve('dddddd')
})
]).then(res => {
console.log(res)
})
promise,promise.all
最新推荐文章于 2024-08-24 11:46:12 发布