Promise的基本用法(demo)

demo:bash

function read(content) {
    console.log("aaa:"+ content);
	
    return new Promise(function (resolve, reject) {
        setTimeout(function () {
            if(content>4){
                resolve(content)
            }else{
                reject(content)
            }
        }, 1000*content)
    })
}

let result = Promise.all([read(5), read(2)]);
result.then((data) => {
    console.log('成功'+data)
},(err)=>{
    console.log('失敗'+err) //失敗2
})
複製代碼

demo2 精簡:ui

function read() {
    var content = 5
    console.log("bbbb:"+ content);
	
    return new Promise(function (resolve) {
        
        resolve(6666)
        
    })
}

read().then((data) => {
    console.log('成功'+data)
    //成功6666
})
複製代碼

end
相關文章
相關標籤/搜索